我知道不建议这样做,但是是否有可能将用户的密码传递给scp?
我想通过scp复制一个文件,作为批处理作业的一部分,接收服务器当然需要密码,不,我不能轻易地将其更改为基于密钥的身份验证。
我知道不建议这样做,但是是否有可能将用户的密码传递给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
其他回答
您可以使用ssh-copy-id添加ssh密钥:
$which ssh-copy-id #check whether it exists
如果存在:
ssh-copy-id "user@remote-system"
如果你观察到一个严格的主机密钥检查错误,那么使用-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
使用sshpass:
sshpass -p "password" scp -r user@example.com:/some/remote/path /some/local/path
所以密码不会显示在bash历史记录中
sshpass -f "/path/to/passwordfile" scp -r user@example.com:/some/remote/path /some/local/path
上面的操作将路径的内容从远程主机复制到本地。
安装:
ubuntu / debian 安装sshpass centos / fedora Yum安装sshpass MAC / macports 端口安装sshpass MAC / brew brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master/Library/Formula/sshpass.rb
Curl可以用作SCP的替代方案来复制文件,并且它支持在命令行上设置密码。
curl --insecure --user username:password -T /path/to/sourcefile sftp://desthost/path/
一旦像上面解释的那样设置了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命令。