SSH密钥登录
- 生成密钥对
root@ttkl:~# ssh-keygen ==》建立密钥对
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): ==》按 Enter
Created directory '/root/.ssh'.
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:I/r1Ugm/cZftWSmfw0ce+05zdWKINQ6kIEdnvzVaKko root@ttkl
The key's randomart image is:
+---[RSA 2048]----+
| ..+ o . |
| o + + |
| . o * |
| . @ + |
| E So=.o oo+|
| o o o= .oo+*|
| . . .. + .+=O|
| . .... O*|
| . .. .*|
+----[SHA256]-----+
- 安装公钥
1、在服务器安装公钥:
root@ttkl:~# cd .ssh
root@ttkl:~/.ssh# cat id_rsa.pub >> authorized_keys
2、修改文件权限
root@ttkl:~/.ssh# chmod 600 authorized_keys
root@ttkl:~/.ssh# chmod 700 ~/.ssh
- 修改SSH配置
1、编辑 /etc/ssh/sshd_config文件
RSAAuthentication yes PubkeyAuthentication yes # root用户登录 PermitRootLogin yes # 禁用密码登录 PasswordAuthentication no
2、重启ssh服务
service sshd restart
- 将私钥下载到客户端即可