Linux_scp 远程复制不需要输入密码
时间:2010-09-27 来源:xiang002
1. 生成密匙对,我用的是rsa的密钥。使用命令 "ssh-keygen -t rsa"
ssh-keygen -t rsa
scp ./.ssh/id_rsa.pub [email protected]:/home/xukun/pub4
cat pub4 >> .ssh/authorized_keys
生成的过程中提示会提示输入一个不同于你的password的密码,直接回车,让它空着,这样以后ssh就不用输入密码了。
其中公共密钥保存在 ~/.ssh/id_rsa.pub
私有密钥保存在 ~/.ssh/id_rsa
2. 然后改一下 .ssh 目录的权限,使用命令 "chmod 755 ~/.ssh" (似乎不需要这步)
3. 之后把这个密钥对中的公共密钥复制到你要访问的机器的相应账号的.ssh目录下,并保存为authorized_keys.
如 [huchao@localhost .ssh]$ scp id_rsa.pub [email protected]:/home/cll/.ssh/authorized_keys
之这样就大功告成了。之后你再用ssh scp sftp 之类的访问那台机器时,就不用输入密码了,用在script上更是方便。
以下是代码片段:ssh-keygen -t rsa
scp ./.ssh/id_rsa.pub [email protected]:/home/xukun/pub4
cat pub4 >> .ssh/authorized_keys
相关阅读 更多 +