我知道不建议这样做,但是是否有可能将用户的密码传递给scp?

我想通过scp复制一个文件,作为批处理作业的一部分,接收服务器当然需要密码,不,我不能轻易地将其更改为基于密钥的身份验证。


当前回答

另一种方法是将用户密钥的公共部分添加到目标系统上的授权密钥文件中。在发起传输的系统上,可以运行ssh-agent守护进程,并将密钥的私有部分添加到代理中。然后可以将批作业配置为使用代理获取私钥,而不是提示输入密钥的密码。

这应该可以在UNIX/Linux系统或Windows平台上使用pageant和pscp实现。

其他回答

Make sure password authentication is enabled on the target server. If it runs Ubuntu, then open /etc/ssh/sshd_config on the server, find lines PasswordAuthentication=no and comment all them out (put # at the start of the line), save the file and run sudo systemctl restart ssh to apply the configuration. If there is no such line then you're done. Add -o PreferredAuthentications="password" to your scp command, e.g.: scp -o PreferredAuthentications="password" /path/to/file user@server:/destination/directory

Curl可以用作SCP的替代方案来复制文件,并且它支持在命令行上设置密码。

curl --insecure --user username:password -T /path/to/sourcefile sftp://desthost/path/

我在这里找到了一个非常有用的答案。

rsync -r -v --progress -e ssh user@remote-system:/address/to/remote/file /home/user/

你不仅可以在那里传递密码,而且它还会在复制时显示进度条。真的太棒了。

如果你观察到一个严格的主机密钥检查错误,那么使用-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null选项。

完整示例如下 sshpass -p "password" scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@domain-name.com:/tmp/from/psoutput /tmp/to/psoutput

没有人提到它,但是Putty scp (pscp)有一个-pw选项作为密码。

文档可以在这里找到:https://the.earth.li/~sgtatham/putty/0.67/htmldoc/Chapter5.html#pscp