I am copying files from a remote server to my local server. Here is the code that does this:
ssh -q username@$192.168.162.156 "su -lc 'cp /copy/from /copy/it/here'"
I am using this code segment in a for loop so it will prompt for a password for every iteration. How do I get the password from the su
command? (without using rsync or sudo). I also don't want any alternatives even if they are better.
Execute in local server:
scp remote_user@remote_server:/path/to/files /dir/to/copy
When executed in local machine, this logon to remote_server as user remote_user and copy the files in /path/to/files/ in remote server to /dir/to/copy/ in local server.
You might want to setup a passwordless ssh connection to run it in a script which requires no passwords.
Read man scp
for more.
您可以通过stdin传递密码:
echo 'password' | su -c [...]
If repetitive promt for password is your problem, you may try
new ssh module
of perl
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.