1.生成私钥
ssh-keygen -t rsa
- 执行后首先提示输入保存位置,不输入为默认位置:
/root/.ssh
- 然后提示输入密码,不输入,无密码
- 再次输入确认密码
root@hi3798mv200:~# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa
Your public key has been saved in /root/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:GV6+PNHNTgnUrC+JHCaKuhpEDaumvVl0JleLOUo8Qqs root@hi3798mv200
The key's randomart image is:
+---[RSA 3072]----+
| . .o |
| + . o |
| o.. o . .. |
|o. o =.*o..+ . |
|.oo *.B.S+oo.o= |
|+o +.B.. .oooo. |
|E ..o + .. |
| ..+ . |
|..+. |
+----[SHA256]-----+
2.进入/root/.ssh/目录,在服务器上安装公钥,执行
cd /root/.ssh/
cat id_rsa.pub >> authorized_keys
3.文件授权
chmod 600 authorized_keys
chmod 700 ~/.ssh
4.编辑 配置文件
vi /etc/ssh/sshd_config
shirt+G跳转底部,在底部加以下代码,:wq保存退出
RSAAuthentication yes
PubkeyAuthentication yes
PermitRootLogin yes
5.当你完成全部设置,并以密钥方式登录成功后,再禁用密码登录
在/etc/ssh/sshd_config 文件 添加以下参数
PasswordAuthentication no
6.重启SSH服务,生效
service sshd restart
人生不如意十之八九,常想一二,不思八九
楼主辛苦了,谢谢楼主,楼主好人一生平安!
感谢分享
给力,试试去