本文是针对普通用户
,root用户设置密钥登录,需要在aliyun
官网设置密钥对。
所以在按照本文操作时,要确保:
- 有一个普通用户
- 普通用户已经有了
sudo
操作权限。(redhat系列加入wheel组,ubuntu加入sudo组)
1、传送公钥到服务器
首先,允许密码登录。在/etc/ssh/sshd_config
中,修改。
PasswordAuthentication yes
然后,通过rsync
使用密码把公钥传送到服务器。
rsync -av /home/jo/.ssh/id_rsa.pub <用户名>@<地址>:/home/<用户名>/.ssh/
最后,把公钥复制到authorized_keys
。
cat id_rsa.pub >> authorized_keys
2、修改配置文件
保证ssh服务器配置文件(默认为/etc/ssh/sshd_config)允许公钥登录,并禁止密码登录。
PubkeyAuthentication yes
PasswordAuthentication no
别忘了重启sshd服务
sudo systemctl restart sshd
3、保证权限正确
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized\_keys
然后就可以通过密钥登录。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。