linux远程登录免password

来源:互联网 发布:淘宝卖家怎么修改中评 编辑:程序博客网 时间:2024/05/21 02:52

 

如果希望从ServerA免输入passwd sshServerB,先在ServerA上执行:

ssh-keygen -t rsa

 

例如:连续回车即可

hanqf@localhost:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/hanqf/.ssh/id_rsa):
Created directory '/home/hanqf/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/hanqf/.ssh/id_rsa.
Your public key has been saved in /home/hanqf/.ssh/id_rsa.pub.
The key fingerprint is:
d5:5a:63:3d:e7:09:d9:34:d5:2b:55:b5:a8:d8:7d:b9 hanqf@localhost

 

结果会在当前用户的家目录下的.ssh目录下面生成两个文件id_rsa.pubid_rsa

id_rsa.pub拷贝到ServerB的用户目录下的.ssh目录下的authorized_keys文件中,

如果ServerB下还没有这个文件,可以执行下面这个命令。

scp id_rsa.pub ServerB:~/.ssh/authorized_keys

例如:

hanqf@localhost:scp id_rsa.pub develop@192.168.1.219:~/.ssh/authorized_keys

develop@192.168.1.219's password:

 


如果ServerB已经有了该文件,请执行下面的命令把SeverAid_rsa.pub的内容添加到该文件中。

scp id_rsa.pub ServerB:~/.ssh/ServerA_rsa.pub
cat ServerA_rsa.pub >> authorized_keys

hanqf@localhost:scp id_rsa.pub develop@192.168.1.219:~/.ssh/192.168.1.219_rsa.pub

develop@192.168.1.219's password:

hanqf@localhost:ssh develop@192.168.1.219

develop@192.168.1.219's password:

develop@localhost: cat 192.168.1.219_rsa.pub >> authorized_keys

 


测试一下儿:

hanqf@localhost:ssh develop@192.168.1.219

Last login:Wed May 13 14:41:43 2009 from 192.168.0.66

develop@localhost:

 

 

如果想从ServerBpassword登录到ServerA,请把上述过程反向操作一遍。

 

 

原创粉丝点击