生产环境:
两台centos6.5系统的主机
A主机:192.168.184.128
B主机:192.168.184.129
在实际生产环境中,无论是登录到哪台主机上,还是想要从某台主机中拷贝资源,都需要在你的终端软件上输入密码,不管你使用的是xshell还是CiscoCRT等等第三方软件,工作量小的情况下还可以,但是工作量大的情况下,就会变的非常繁琐,那么有什么方法可以免密码拷贝文件呢?
接下来配置公钥和私钥的方式来进行免密码拷贝!!!
(1.)进到~/.ssh文件下面执行ssh-keygen -t rsa生成秘钥对
ssh-keygen -t rsa
(2.)将生成好的公钥上传到129主机上~/.ssh/文件中。
[root@file ~]# cd ~/.ssh/ [root@file .ssh]# ls id_rsa id_rsa.pub known_hosts [root@file .ssh]# scp -P 20002 id_rsa.pub [email protected]:~/.ssh/ The authenticity of host '192.168.184.129 (192.168.184.129)' can't be established. RSA key fingerprint is f7:8d:3d:ad:d9:50:36:0e:05:9a:fa:b2:2d:cc:f0:4c. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.184.129' (RSA) to the list of known hosts. [email protected]'s password: id_rsa.pub 100% 402 0.4KB/s 00:00 [root@file .ssh]#
(3.)进入129服务器,将128上生成的公钥导入到129主机~/.ssh/authorized_keys文件中。
(4.)~/.ssh权限设置为700 ,~/.ssh/authorized_keys的权限设置为600
这是linux的安全要求,如果权限不对,自动登录将不会生效
完毕之后,退出服务器的登录,再使用ssh登录,你就会发现服务器不会再向你询问密码了.
(6.)验证免密拷贝文件
(7.)到129上面去查看发送的test文件是否存在。
声明:一切环境都在root下执行,如果是个人用户环境下首先要创建此用户,再授权属主属组相关权限即可!