• 周一. 8月 15th, 2022

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

linux设置秘钥登录

admin

11月 28, 2021

1、在linux服务器生成公钥和私钥

[[email protected] .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 [email protected]
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 [email protected]192.168.50.131
ssh 192.168.50.131

发表回复

您的电子邮箱地址不会被公开。