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

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


当前回答

从Windows以非交互方式使用SCP:

安装社区版netcmdlets 导入模块 使用Send-PowerShellServerFile -AuthMode password -User MyUser -Password not-secure -Server YourServer -LocalFile C:\downloads\test.txt -RemoteFile C:\temp\test.txt发送非交互式密码的文件

其他回答

只需生成一个SSH密钥:

ssh-keygen -t rsa -C "your_email@youremail.com"

复制~/.ssh/id_rsa.pub的内容 最后将它添加到远程计算机~/.ssh/authorized_keys

确保远程机器拥有~的权限0700。~/.ssh/authorized_keys文件夹为0600

您可以使用以下步骤。这对我很管用!

步骤1 - 创建一个普通的文件,假设“fileWithScpPassword”,其中包含目标服务器的ssh密码。

Step2-使用sshpaas -f后跟密码文件名,然后是正常的scp命令。

sshpass -f“scppassword”scp / filepathtou上传user@ip:/目的地目的地/

一旦像上面解释的那样设置了ssh-keygen,就可以这样做了

SCP -i ~/。Ssh /id_rsa /local/path/to/file remote@ip.com:/path/in/remote/server/

如果希望减少每次输入的次数,可以修改.bash_profile文件并将

alias remote_scp='scp -i ~/.ssh/id_rsa /local/path/to/file remote@ip.com:/path/in/remote/server/

然后从您的终端执行source ~/.bash_profile。然后,如果您在终端中输入remote_scp,它应该运行没有密码的scp命令。

您可以使用ssh-copy-id添加ssh密钥:

$which ssh-copy-id #check whether it exists

如果存在:

ssh-copy-id  "user@remote-system"

如果您从Windows连接到服务器,Putty版本的scp(“pscp”)允许您使用-pw参数传递密码。

这里的文档中提到了这一点。