简体   繁体   中英

How do I get the password from the su command?

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

  1. Create passwordless ssh setup between host
  2. Use new ssh module of perl
  3. Tar all you files and then send it over network. This way only one tar file is send and password prompt will only be for once.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM