Arg*_*gel 261 linux scp io-redirection
我知道不推荐,但是可以将用户的密码传递给scp吗?
我想通过scp复制文件作为批处理作业的一部分,接收服务器当然需要密码,不,我不能轻易地将其更改为基于密钥的身份验证.
Kev*_*inS 481
使用sshpass:
sshpass -p "password" scp -r user@example.com:/some/remote/path /some/local/path
Run Code Online (Sandbox Code Playgroud)
或者,密码不会显示在bash历史记录中
sshpass -f "/path/to/passwordfile" scp -r user@example.com:/some/remote/path /some/local/path
Run Code Online (Sandbox Code Playgroud)
以上复制从远程主机到本地的路径内容.
安装:
apt install sshpass
yum install sshpass
port install sshpass
brew install https://raw.githubusercontent.com/kadwanev/bigboybrew/master??/Library/Formula/ssh??pass.rb
mus*_*ran 43
只需生成一个ssh键,如:
ssh-keygen -t rsa -C "your_email@youremail.com"
Run Code Online (Sandbox Code Playgroud)
复制内容~/.ssh/id_rsa.pub
并最后将其添加到远程计算机~/.ssh/authorized_keys
确保远程计算机具有权限0700 for ~./ssh folder
和0600 for ~/.ssh/authorized_keys
小智 35
如果从Windows连接到服务器,则scty("pscp")的Putty版本允许您使用-pw
参数传递密码.
小智 22
curl可以用作scp的替代方法来复制文件,它支持命令行上的密码.
curl --insecure --user username:password -T /path/to/sourcefile sftp://desthost/path/
Run Code Online (Sandbox Code Playgroud)
Pra*_*eet 21
您可以在unix/terminal上使用'expect'脚本
例如,创建'test.exp':
#!/usr/bin/expect
spawn scp /usr/bin/file.txt root@<ServerLocation>:/home
set pass "Your_Password"
expect {
password: {send "$pass\r"; exp_continue}
}
Run Code Online (Sandbox Code Playgroud)
运行脚本
expect test.exp
Run Code Online (Sandbox Code Playgroud)
我希望有所帮助.
Esp*_*spo 10
以下是使用expect
工具执行此操作的示例:
sub copyover {
$scp=Expect->spawn("/usr/bin/scp ${srcpath}/$file $who:${destpath}
+/$file");
$scp->expect(30,"ssword: ") || die "Never got password prompt from
+ $dest:$!\n";
print $scp 'password' . "\n";
$scp->expect(30,"-re",'$\s') || die "Never got prompt from parent
+system:$!\n";
$scp->soft_close();
return;
}
Run Code Online (Sandbox Code Playgroud)
小智 7
没有人提到它,但是Putty scp(pscp)有一个-pw选项用于输入密码.
可在此处找到文档:https: //the.earth.li/~sgtatham/putty/0.67/htmldoc/Chapter5.html#pscp
小智 5
您可以使用ssh-copy-id
添加 ssh 密钥:
$which ssh-copy-id #check whether it exists
Run Code Online (Sandbox Code Playgroud)
如果存在:
ssh-copy-id "user@remote-system"
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
613122 次 |
最近记录: |