scp noneed passwd
经常在不同linux机器之间互相scp拷文件,每次总是要输入密码才可行。
通过ssh-keygen生成公钥,在两台机器之间互相建立信任通道即可。
假设本地机器client,远程机器为server。
1. 生成rsa keygen
[winter@client winter] $ ssh-keygen -b 1024 -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/winter/.ssh/id_rsa): <Enter>
Enter passphrase (empty for no passphrase): <Enter>
Enter same passphrase again: <Enter>
Your identification has been saved in /home/winter/.ssh/id_rsa.
Your public key has been saved in /home/winter/.ssh/id_rsa.pub.
The key fingerprint is:
33:d4:7b:9c:87:04:cf:14:40:22:6d:c7:15:78:97:6a winter@client
直接上面公钥和私钥存放地址可以直接回车,私钥密码可以直接回车,也可以输入。
2. 查看.ssh目录下了多私钥和公钥文件
[winter@client winter] $ ls .ssh/
id_rsa id_rsa.pub known_hosts
3. 拷贝公钥到目标机器上,并改名成authorized_keys
[winter@client winter] $ scp .ssh/id_rsa.pub server@192.168.0.110:/home/server/.ssh/authorized_keys
如果多人用一个服务器,那么只需要把自己生成的id_rsa.pub的内容>>到服务器的authorized_keys里就行了
4.如果出现Agent admitted failure to sign using the key 问题:
解決方法:
使用 ssh-add 指令將私钥加进来(根据个人的密匙命名不同更改 id_rsa)
# ssh-add ~/.ssh/id_rsa