【Linux】免密登录

1.生成密钥

ssh-keygen -t rsa -C "<填写自己方便识别的注释>" -b 4096  没什么问题就执行三次空格。 
三次问题是1.填入生成密钥对的路径名字。2 填入自定义passphrsa。3确认。 

 1 [root@localhost home]# ssh-keygen -t rsa -C "********" -b 4096
 2 Generating public/private rsa key pair.
 3 Enter file in which to save the key (/root/.ssh/id_rsa): 
 4 Enter passphrase (empty for no passphrase): 
 5 Enter same passphrase again: 
 6 Your identification has been saved in /root/.ssh/id_rsa.
 7 Your public key has been saved in /root/.ssh/id_rsa.pub.
 8 The key fingerprint is:
 9 SHA256:oQYIN3KUkPmnCn0LrC25h5L0yVpiIvoHUgawDuyCKuE **************
10 The key's randomart image is:
11 +---[RSA 4096]----+
12 |*==.             |
13 |=*.o             |
14 |o+. .   .        |
15 |= + .. . .       |
16 |+B o  o S        |
17 |*o* ..           |
18 |BEo=..           |
19 |# =+o            |
20 |+*o.             |
21 +----[SHA256]-----+

2.生成的公钥和私钥在/root/.ssh目录下

1 [root@localhost .ssh]# pwd
2 /root/.ssh
3 [root@localhost .ssh]# ls -l
4 总用量 12
5 -rw-------. 1 root root 3247 9月  19 10:00 id_rsa       #私钥
6 -rw-r--r--. 1 root root  746 9月  19 10:00 id_rsa.pub   #公钥
7 -rw-r--r--. 1 root root  174 9月  18 16:58 known_hosts

3.将公钥id_rsa.pub复制到远程主机/root/.ssh/文件中,并且重命名为authorized_keys。

  • scp  /root/.ssh/id_rsa.pub   root@远程ip:/root/.ssh/authorized_keys

  • ssh-copy-id  -i  ~/.ssh/id_rsa.pub root@远程ip

验证密码即可

4.连接

  • ssh 远程ip

5.免确认机器指纹(不加入known_hosts)

  • ssh -o StrictHostKeyChecking=no 远程ip

猜你喜欢

转载自www.cnblogs.com/jxd283465/p/11653899.html