設置 ssh 無密碼登錄
- 檢查現有 SSH 密鑰對。
> ls -al ~/.ssh/id_*.pub
> No such file or directory
- 生成新的 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):
ls ~/.ssh/id_*/home/yourusername/.ssh/id_rsa /home/yourusername/.ssh/id_rsa.pub
- 復制公鑰。
> 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"
- 使用 SSH 密鑰登錄到你的服務器。
> ssh rumenz@rumenz.com
禁用 SSH 密碼認證
- 以具有 sudo 權限或 root 的用戶身份使用 SSH 密鑰登錄遠程服務器:
> ssh sudo_user@server_ip_address
- 打開 SSH 配置文件 /etc/ssh/sshd_config,搜索如下指令,修改如下:
> vim /etc/ssh/sshd_config PasswordAuthentication no ChallengeResponseAuthentication no UsePAM no
> systemctl restart ssh
> systemctl restart sshd
? 版權聲明
文章版權歸作者所有,未經允許請勿轉載。
THE END