linux如何设置无密码SSH登录

设置 ssh 无密码登录

  1. 检查现有 SSH 密钥对。
> ls -al ~/.ssh/id_*.pub
> No such file or directory
  1. 生成新的 SSH 密钥对。
> ssh-keygen -t rsa -b 4096 -C "your_email@domain.com"
> Enter file in which to save the key (/home/yourusername/.ssh/id_rsa):
> Enter passphrase (empty for no passphrase):

linux如何设置无密码SSH登录

ls ~/.ssh/id_*/home/yourusername/.ssh/id_rsa /home/yourusername/.ssh/id_rsa.pub
  1. 复制公钥。
> ssh-copy-id rumenz@rumenz.com
> rumenz@rumenz.com's password:
> cat ~/.ssh/id_rsa.pub | ssh rumenz@rumenz.com "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
  1. 使用 SSH 密钥登录到你的服务器。
> ssh rumenz@rumenz.com

禁用 SSH 密码认证

  1. 以具有 sudo 权限或 root 的用户身份使用 SSH 密钥登录远程服务器:
> ssh sudo_user@server_ip_address
  1. 打开 SSH 配置文件 /etc/ssh/sshd_config,搜索如下指令,修改如下:
> vim /etc/ssh/sshd_config PasswordAuthentication no ChallengeResponseAuthentication no UsePAM no
> systemctl restart ssh
> systemctl restart sshd

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享