本文是針對普通用戶
,root用戶設置密鑰登陸,須要在aliyun
官網設置密鑰對。ubuntu
因此在按照本文操做時,要確保:服務器
sudo
操做權限。(redhat系列加入wheel組,ubuntu加入sudo組)首先,容許密碼登陸。在/etc/ssh/sshd_config
中,修改。ssh
PasswordAuthentication yes
而後,經過rsync
使用密碼把公鑰傳送到服務器。rest
rsync -av /home/jo/.ssh/id_rsa.pub <用戶名>@<地址>:/home/<用戶名>/.ssh/
最後,把公鑰複製到authorized_keys
。code
cat id_rsa.pub >> authorized_keys
保證ssh服務器配置文件(默認爲/etc/ssh/sshd_config)容許公鑰登陸,並禁止密碼登陸。io
PubkeyAuthentication yes PasswordAuthentication no
別忘了重啓sshd服務登錄
sudo systemctl restart sshd
chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized\_keys
而後就能夠經過密鑰登陸。配置