SSH, SCP 不输入密码

经常在不同linux机器之间互相scp拷文件,每次总是要输入密码才可行。

通过ssh-keygen生成公钥,在两台机器之间互相建立信任通道即可。假设本地机器client,远程机器为server。

生成rsa keygen

chenming@chenming-Aspire-5830TG:~$ ssh-keygen -b 1024 -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/chenming/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/chenming/.ssh/id_rsa.
Your public key has been saved in /home/chenming/.ssh/id_rsa.pub.
The key fingerprint is:
0c:b7:ee:05:c1:bb:5b:3f:f1:7f:49:8f:64:23:ad:c2 chenming@chenming-Aspire-5830TG
The key's randomart image is:
+--[ RSA 1024]----+
|                 |
|       .         |
|      . +        |
|       + +       |
|        S    .   |
|       . o  o =. |
|        o.o  B.oo|
|       . +E.o o.o|
|        o  ... .o|
+-----------------+

直接上面公钥和私钥存放地址可以直接回车,私钥密码可以直接回车,也可以输入。

查看.ssh目录下了多私钥和公钥文件

chenming@chenming-Aspire-5830TG:~$ ls .ssh
id_rsa  id_rsa.pub  known_hosts

拷贝公钥到目标机器上,并改名成 authorized_keys

scp ~/.ssh/id_rsa.pub kyle.ai:/root/.ssh/authorized_keys

首次scp命令时候还是会提示输入密码,还有是否继续链接的提示,以后就可以直接进去。