这是我目前的做法:
# ssh-keygen -t dsa -b 1024 -f /root/localhost-rsnapshot-key Enter passphrase (empty for no passphrase): [press enter here] Enter same passphrase again: [press enter here] # if [ ! -d ~/.ssh ]; then mkdir ~/.ssh ; chmod 700 ~/.ssh ; fi # cd ~/.ssh/ # if [ ! -f config ]; then touch config ; chmod 600 config ; fi # echo Host server2 >> config # echo Hostname server2.domain.tld >> config # echo IdentityFile /root/localhost-rsnapshot-key >> config
现在当我运行rsnapshop像:
backup [email protected]:/home/ localhost/server2/
我得到以下内容:
rsnapshot hourly reverse mapping checking getaddrinfo for server2-domain-tld.1-2-3-4 [1.2.3.4] failed - POSSIBLE BREAK-IN ATTEMPT! [email protected]'s password:
有没有办法让这个没有密码运行?
您可以从server1运行命令ssh-copy-id [email protected]将您的身份文件复制到远程系统并允许进行公钥authentication。 您可能还需要确保在您的sshdconfiguration中启用基于密钥的身份validation。
在server2上,您需要将生成的公钥添加到/root/.ssh/authorized_keys
假设您想要在名为“server2”的主机上对名为“server2”的shell帐户进行身份validation,则需要将server1上生成的localhost-rsnapshot-key.pub的内容添加到server2:/home/server2/.ssh/authorized_keys文件。
首先,请考虑使用RSA密钥,而不是DSA,虽然我知道这是不请自来的build议,RSA比DSA更安全,除非你有一个令人信服的理由这样做。
让我开始说我会使用像scp,cat,chmod,chown等非标准命令,而不是像ssh-copy-id那样使用更深奥的命令。 所以你可以在任何Unix上使用它,而不仅仅是Linux。
在运行ssh-keygen命令后,将这些文件ssh-keygen ,在.ssh目录中有两个文件:
id_dsa的
id_dsa.pub
# on the local machine which will connect the remote server without a password cd ${HOME}/.ssh scp id_dsa.pub ${REMOTE_SERVER}:${REMOTE_USER_HOME}/.ssh # if this errors out, you might need to create the .ssh on the remote server # # on the remote machine which will accept incoming ssh connection without a password chown ${REMOTE_USER} ${REMOTE_USER_HOME} # this should already be set like this chown ${REMOTE_USER} ${REMOTE_USER_HOME}/.ssh # if this exists, it should be this way chmod 700 ${REMOTE_USER_HOME} chmod 700 ${REMOTE_USER_HOME}/.ssh cd ${REMOTE_USER_HOME}/.ssh cat id_dsa.pub >> ./authorized_keys chown ${REMOTE_USER} ./authorized_keys chmod 600 ./authorized_keys
现在,您应该可以连接到远程机器而无需密码。
希望这可以帮助。
虽然已经在上面的几个答案中解释了,但是如果你想了解更多的细节,可以参考这篇文章。
无密码login