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

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


当前回答

一旦像上面解释的那样设置了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命令。

其他回答

确保你有“期望”工具之前,如果没有,就这样做 # apt-get install expect 创建具有以下内容的脚本文件。(# vi /root/脚本文件) 生成SCP /path_from/file_name user_name_here@to_host_name:/path_to 预计“密码: 发送put_password_here \ n; 交互 使用“expect”工具执行脚本文件 # expect /root/scriptfile

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

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

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

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

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

如果存在:

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

将文件从一个服务器复制到另一个服务器(在脚本上)

在ubuntu或其他Linux机器上安装putty。Putty随pscp附带。我们可以用pscp复制文件。

apt-get update
apt-get install putty 
echo n |  pscp -pw "Password@1234" -r user_name@source_server_IP:/copy_file_path/files /path_to_copy/files

有关更多选项,请参阅pscp help。

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

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

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

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