0%

如何使执行scp命令时不需要输入用户密码

首先制作密码匙∶
ssh-keygen -t rsa 按三次 Return 键

1
scp ~/.ssh/ida_dsa.pub username@somewhere.com:~/.ssh/authorized_keys2
1
2
3
4
5
6
7
8
9
$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:
$49:9c:8a:8f:bc:19:5e:8c:c0:10:d3:15:60:a3:32:1c root@Client

假如 ~/.ssh/ida_dsa.pub 已经存在,可以直接 scp 到 remote 主机,放于 ~/.ssh/ 下并改名做 authorized_keys2。而 Remote 主机已有 ~/.ssh/authorized_keys2 的话,则可先上存 ida_dsa.pub,然后用:
cat ida_dsa.pub >> authorized_keys2

这样,以后使用 ssh 或 scp 也不需要再键入密码。