我知道不建议这样做,但是是否有可能将用户的密码传递给scp?
我想通过scp复制一个文件,作为批处理作业的一部分,接收服务器当然需要密码,不,我不能轻易地将其更改为基于密钥的身份验证。
我知道不建议这样做,但是是否有可能将用户的密码传递给scp?
我想通过scp复制一个文件,作为批处理作业的一部分,接收服务器当然需要密码,不,我不能轻易地将其更改为基于密钥的身份验证。
当前回答
如果您从Windows连接到服务器,Putty版本的scp(“pscp”)允许您使用-pw参数传递密码。
这里的文档中提到了这一点。
其他回答
确保你有“期望”工具之前,如果没有,就这样做 # 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
您可以使用像expect这样的工具编写脚本(也有方便的绑定,比如Python的Pexpect)。
只需生成一个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:/目的地目的地/
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