1、在linux服务器生成公钥和私钥
[root@localhost .ssh]# ssh-keygen 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: 02:54:da:3a:4e:d4:21:44:9c:f6:47:22:db:50:71:77 root@localhost.localdomain The key's randomart image is: +--[ RSA 2048]----+ | +=+=.. . E | | .*=.o.. . | | .+*oo | | ..oo . | | + ..S | | o . . | | . | | | | | +-----------------+
2、配置文件开启秘钥登录
cat /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
systemctl restart sshd
3、创建认证文件
touch .ssh/authorized_keys chmod 700 .ssh/authorized_keys
cat .ssh/id_rsa.pub >> .ssh/authorized_keys
4、win客户端秘钥登录
将.ssh/id_rsa下载到win客户端
通过Xshell等工具将秘钥导入
选择导入秘钥登录即可
5、linux客户端秘钥登录
将公钥复制到linux客户端
cd .ssh ssh-copy-id -i id_rsa.pub root@192.168.50.131 ssh 192.168.50.131