一台linux服务往另外一台服务器scp文件时经常要提示输入密码,这样感觉很繁琐,于是添加互信机制

把你的本地主机用户的ssh公匙文件复制到远程主机用户的~/.ssh/authorized_keys文件中,假设本地主机linux(10.1.1.1),远程主机linux(10.1.1.2)

一,在linux100主机里的用户

运行

#ssh-keygen -t rsa

结果如下

Generating public/private rsa key pair.

Enter file in which to save the key(/home/.username/ssh/id_rsa):#回车

Enter passphrase (empty for no passphrase):#回车

Enter same passphrase again:#回车

Your identification has been saved in /home/.username/.ssh/id_rsa.

Your public key has been saved in /home/.username/.ssh/id_rsa.pub.

The key fingerprint is:

38:25:c1:4d:5d:d3:89:bb:46:67:bf:52:af:c3:17:0c username@localhost

Generating RSA keys:

Key generation complete.

会在用户目录~/.ssh/产生两个文件,id_rsa,id_rsa.pub

二,把linux(10.1.1.1)主机上的id_rsa.pub文件拷贝到linux(10.1.1.2)主机的root用户主目录下的.ssh目录下,并且改名为authorized_keys

即:

/root/.ssh/authorized_keys

这样在linux100主机上使用scp命令复制文件到linux(10.1.1.2)上将不提示输入密码了,直接复制了。反之亦然!


转自:

<http://blog.163.com/ji_1006/blog/static/106123412015321102632355/

另外,可以使用cat id_rsa.pub>>authorized_keys把另一台机器的公钥添加到authorized_keys文件里。

例如多台服务器对某一台实现互信, 65、66、67 -> 24

转自:

<http://www.dataguru.cn/thread-95673-1-1.html



Logo

更多推荐