因为需要无密码登录,在ubuntu下,用非root设置好也可以,但需要保证所有程序及相关目录的属主必须是此非root用户。
当设置无密码登录时需要分别设置普通用户和root下。
另附无密码登录设置文档:
生成密匙对,我用的是rsa的密钥。使用命令 "ssh-keygen -t rsa"
[root@test ~]$ 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:
46:ed:89:18:f8:30:04:41:f5:72:b2:e6:66:27:20:73 root@test.test.com
[root@test ~]$
生成的过程中提示输入密钥对保存位置,直接回车,接受默认值就行了。接着会提示输入一
个不同于你的password的密码,直接回车,让它空着。 这样,密钥对就生成完了。
其中公共密钥保存在 ~/.ssh/id_rsa.pub
私有密钥保存在 ~/.ssh/id_rsa
然后改一下 .ssh 目录的权限,使用命令 "chmod 755 ~/.ssh"
[root@test ~]$ chmod 755 ~/.ssh
[root@test ~]$
之后把这个密钥对中的公共密钥复制到你要访问的机器上去,并保存为
~/.ssh/authorized_keys
[root@test ~]$ scp ~/.ssh/id_rsa.pub test2:/root/.ssh/authorized_keys
cat id_rsa.pub >>authorized_keys