SCP 实现信任连接

来源:互联网 发布:linux vim 跳到指定行 编辑:程序博客网 时间:2024/05/17 03:34

通常用scp命令通过ssh获取对方linux主机文件的时候都需要输入密码确认,如果需要在主机上做一个自动获取文件的shell脚本,这样显然是不行的,通过下面的设置,可以不需要输入密码,直接获到文件。
这里假设主机A用来获到主机B的文件。
1. 在主机A上执行如下命令来生成配对密钥:
#ssh-keygen -t rsa
显示信息如下:
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory ‘/root/.ssh’.
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:
45:13:ec:31:f9:3d:25:54:7b:5f:03:40:ba:e9:76:cd root@localhost
按三次回车。
2. 为 ~/.ssh 目录设置权限:
#chmod -R 755 .ssh(A/B主机都做)
将 .ssh 目录中的 id_rsa.pub 文件复制到 主机B 的 ~/.ssh/ 目录中,并改名为 authorized_keys ,同样给该目录设置权限。
#.chmod 600 ~/.ssh/id_rsa(在A上操作)
这一步至关重要,不然操作不会生效
3. 到主机A中执行命令和主机B建立信任,例(假设主机B的IP为:192.168.0.3):
#scp ~/.ssh/id_rsa.pub 192.168.0.3:/root/.ssh/authorized_keys
4. 下面就可以用scp命令不需要密码来获取主机B的文件了

 

http://os.51cto.com/art/201003/187301.htm

http://blog.163.com/jgh2008@126/blog/static/28596246200851952131138/

原创粉丝点击