本文是针对普通用户
,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
而后就能够经过密钥登陆。配置