Linux上SSH登录远程服务器免密码

  在本地的客户端SSH到远程服务端时,每次都要输入用户名和密码,如果不想每次都输入密码则可以使用以下操作。

  首先在本地的客户端输入 ssh-keygen

[keysystem@localhost ~]$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/keysystem/.ssh/id_rsa): 
Created directory '/home/keysystem/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/keysystem/.ssh/id_rsa.
Your public key has been saved in /home/keysystem/.ssh/id_rsa.pub.
The key fingerprint is:
af:a4:d5:4d:96:3c:24:71:ea:37:47:0c:51:3b:ba:2b keysystem@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
|          . +o.  |
|           + o . |
|          o . =  |
|         . + + . |
|        S . X .  |
|         o = =   |
|        o o o    |
|       + .E  .   |
|      . .  ..    |
+-----------------+
[keysystem@localhost ~]$ 

生成公私钥对,可以进入到~/.ssh目录下查看生成的公私钥对。

[keysystem@localhost ~]$ cd ~/.ssh/
[keysystem@localhost .ssh]$ ll -rlt
total 8
-rw-r--r--. 1 keysystem keysystem  413 Dec  4 22:12 id_rsa.pub
-rw-------. 1 keysystem keysystem 1675 Dec  4 22:12 id_rsa
[keysystem@localhost .ssh]$ 

然后执行 ssh-copy-id dzy@172.20.16.42,其中dzy为远程主机的用户名,172.20.16.42为远程服务器的IP地址。

[keysystem@localhost ~]$ ssh-copy-id dzy@172.20.14.42

 

posted @ 2017-12-04 22:16  alsodzy  阅读(1222)  评论(0编辑  收藏  举报