概述
用命令ssh-keygen -t rsa在
serverA中生成密钥对,-t rsa表示采用RSA算法来生成密钥对.生成的密钥对默认存放在~/.ssh/目录中,id_rsa.pub中存放公钥,id_rsa存放私钥.
(注:在生成密钥对的时候系统会提示输入密钥对的密码,这里请直接回车,不要输入密码,否则后面打通通道之后仍然需要密码,只不过是用这里设置的密码而已)
将id_rsa.pub中的公钥拷贝出来,追加到 serverB中的~/.ssh/authorized_keys文件中.
本机ssh打通自己:
zj@debian-zj:~/repos$ cd ~
zj@debian-zj:~$ 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 zj@debian-zj
The key's randomart p_w_picpath is:
+--[ RSA 2048]----+
| xxxxxxxxxx |
| xxxxxxxxxx |
| xxxxxxxxxxx |
| xxxxxxxxxxxx |
| xxxxxxxxxxxx |
| xxxxxxxxxxx |
|xxxxxxxxxxxx |
|xxxxxx |
|xxxx |
+-----------------+
zj@debian-zj:~$ cd ~/.ssh
zj@debian-zj:~/.ssh$ ls
id_rsa id_rsa.pub known_hosts
zj@debian-zj:~/.ssh$ touch authorized_keys
zj@debian-zj:~/.ssh$ cat id_rsa.pub > authorized_keys
test:
zj@debian-zj:~/.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.
zj@debian-zj:~$ exit
logout
Connection to 127.0.0.1 closed.
zj@debian-zj:~/.ssh$
说明:
authorized_keys文件的权限很重要,如果设置为777,那么登录的时候,还是需要提供密码的。
chmod 400 authorized_keys
(注:在生成密钥对的时候系统会提示输入密钥对的密码,这里请直接回车,不要输入密码,否则后面打通通道之后仍然需要密码,只不过是用这里设置的密码而已)
将id_rsa.pub中的公钥拷贝出来,追加到 serverB中的~/.ssh/authorized_keys文件中.
本机ssh打通自己:
zj@debian-zj:~/repos$ cd ~
zj@debian-zj:~$ 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 zj@debian-zj
The key's randomart p_w_picpath is:
+--[ RSA 2048]----+
| xxxxxxxxxx |
| xxxxxxxxxx |
| xxxxxxxxxxx |
| xxxxxxxxxxxx |
| xxxxxxxxxxxx |
| xxxxxxxxxxx |
|xxxxxxxxxxxx |
|xxxxxx |
|xxxx |
+-----------------+
zj@debian-zj:~$ cd ~/.ssh
zj@debian-zj:~/.ssh$ ls
id_rsa id_rsa.pub known_hosts
zj@debian-zj:~/.ssh$ touch authorized_keys
zj@debian-zj:~/.ssh$ cat id_rsa.pub > authorized_keys
test:
zj@debian-zj:~/.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.
zj@debian-zj:~$ exit
logout
Connection to 127.0.0.1 closed.
zj@debian-zj:~/.ssh$
说明:
authorized_keys文件的权限很重要,如果设置为777,那么登录的时候,还是需要提供密码的。
chmod 400 authorized_keys
转载于:https://blog.51cto.com/zhangjunhd/156307
最后
以上就是震动心锁为你收集整理的ssh打通通道的全部内容,希望文章能够帮你解决ssh打通通道所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复