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 分享