两条命令实现SSH免密码直连服务器

下面操作都在本地Linux终端上进行,不用修改服务器上的配置,一共就两步就搞定

生成ssh密钥文件

ssh-keygen -t rsa
[root@tjnw .ssh]# 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:2t5TDif5z095N9NyUmP7qjztJv1IiLVZ5dwaLxPa2VA root@tjnw
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|                 |
|                E|
|               =.|
|        S  .. =o=|
|       o  +ooB.X=|
|      . . .B=oX=O|
|       . ...=o+O*|
|        . ..oB*++|
+----[SHA256]-----+

上传密钥到服务器

ssh-copy-id [email protected]
[root@tjnw .ssh]# ssh-copy-id [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password:		**输入服务器密码**

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

结束语

以后都可以直接在本地使用ssh 192.168.1.1进行连接,不用输入密码直接连上.

发布了181 篇原创文章 · 获赞 82 · 访问量 41万+

猜你喜欢

转载自blog.csdn.net/lpwmm/article/details/103914774