两台服务器之间scp无密码拷贝文件

在Linux运维工作中,经常会碰到这样的情况,需要安装很多软件,然后这些软件的源代码在其他服务器上面有保存,scp一下,省事,如果两台服务器之间传输文件的次数多了,每次都需要输入密码,麻烦。于是乎,在想如何让服务器之间无密码scp呢?
cp 在两台主机之间相互之间拷贝文件,还是方面!但是需要密码!怎么样才能无密码相互之间拷贝文件呢!
以下就实现是方法!在A主机上运行

ssh-keygen -t  rsa
[root@tiboo2 proxy_cache_dir]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
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:
75:1a:5d:ae:18:d8:65:98:43:12:39:ec:5d:fe:e7:f7 root@tiboo2
[root@tiboo2 proxy_cache_dir]# scp /root/.ssh/id_rsa.pub root@192.168.10.174:/root/.ssh/authorized_keys
The authenticity of host '192.168.10.174 (192.168.10.174)' can't be established.
RSA key fingerprint is 54:f6:0e:aa:35:95:36:bd:f2:6c:aa:6b:8f:04:0a:d4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.10.174' (RSA) to the list of known hosts.
root@192.168.10.174's password:
id_rsa.pub                                  100%  393     0.4KB/s   00:00
OK,再用scp命令测试一下
[root@tiboo2 soft]# scp keepalived-1.2.1.tar.gz root@192.168.10.174:/data/soft/
keepalived-1.2.1.tar.gz                     100%  234KB 233.8KB/s   00:00

这样会在/root/.ssh/有两个 id_rsa ,id_rsa.pub.

将id_rsa.pub复制目标服务器上的/root/.ssh/里,并改名authorized_keys
例如 scp /root/.ssh/is_rsa.pub root@B:/root/.ssh/authorized_keys
这样再次scp的时候,就不需要密码了。

 

您可以选择一种方式赞助本站

支付宝转账赞助

支付宝扫一扫赞助

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

图片 表情