scp'ing 使用密钥文件作为参数,如果可能,我该怎么做?

61 linux ssh scp

scp -i ~/.ssh/id_rsa.pub events*$date*_QA.log $remote_user@$remote_server:$remote_location
Run Code Online (Sandbox Code Playgroud)

上面的脚本不正确吗?我做得不对吗?

我去了.ssh目录,看到远程服务器在known_hosts文件中。

但是,当我做没有任何文件作为参数的普通 scp 时,它仍然要求输入密码

scp events*$date*_QA.log $remote_user@$remote_server:$remote_location
Run Code Online (Sandbox Code Playgroud)

如何在我的命令中包含密钥文件?

sh-3.2$ grep server ~/.ssh/*
/home/user/.ssh/known_hosts:server....com,ip_addr ssh-rsa Asine=jhjsdhfjsadhfjkashdfjhasdjfhksadjfhasjdfhj
Run Code Online (Sandbox Code Playgroud)

whi*_*ark 73

 -i identity_file
         Selects the file from which the identity (private key) for public
         key authentication is read.  This option is directly passed to
         ssh(1).
Run Code Online (Sandbox Code Playgroud)

使用~/.ssh/id_rsa.

  • 您可能必须使用实际路径,如 /home/user/ 而不是 ~。这似乎使它对我有用。 (2认同)