天天看点

ssh打通通道

用命令ssh-keygen -t rsa在 serverA中生成密钥对,-t rsa表示采用RSA算法来生成密钥对.生成的密钥对默认存放在~/.ssh/目录中,id_rsa.pub中存放公钥,id_rsa存放私钥.

(注:在生成密钥对的时候系统会提示输入密钥对的密码,这里请直接回车,不要输入密码,否则后面打通通道之后仍然需要密码,只不过是用这里设置的密码而已)

将id_rsa.pub中的公钥拷贝出来,追加到 serverB中的~/.ssh/authorized_keys文件中.

本机ssh打通自己:

[email protected]:~/repos$ cd ~

[email protected]:~$ ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/home/zj/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/zj/.ssh/id_rsa.

Your public key has been saved in /home/zj/.ssh/id_rsa.pub.

The key fingerprint is:

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX [email protected]

The key's randomart p_w_picpath is:

+--[ RSA 2048]----+

|  xxxxxxxxxx     |

|  xxxxxxxxxx     |

|  xxxxxxxxxxx    |

|   xxxxxxxxxxxx  |

|  xxxxxxxxxxxx   |

| xxxxxxxxxxx     |

|xxxxxxxxxxxx     |

|xxxxxx           |

|xxxx             |

+-----------------+

[email protected]:~$ cd ~/.ssh

[email protected]:~/.ssh$ ls

id_rsa  id_rsa.pub  known_hosts

[email protected]:~/.ssh$ touch authorized_keys

[email protected]:~/.ssh$ cat id_rsa.pub > authorized_keys

test:

[email protected]:~/.ssh$ ssh 127.0.0.1

Linux debian-zj 2.6.26-1-686 #1 SMP Fri Mar 13 18:08:45 UTC 2009 i686

The programs included with the Debian GNU/Linux system are free software;

the exact distribution terms for each program are described in the

individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent

permitted by applicable law.

You have new mail.

[email protected]:~$ exit

logout

Connection to 127.0.0.1 closed.

[email protected]:~/.ssh$

说明:

authorized_keys文件的权限很重要,如果设置为777,那么登录的时候,还是需要提供密码的。

chmod  400 authorized_keys

转载于:https://blog.51cto.com/zhangjunhd/156307

继续阅读