-1

I want to sync some files from a remote server to local system. Because the files are large, it may last for several hours, so i want to run it as nohup:

nohup rsync -r <user>@<remote>:<dir> <local-dir> &

The problem is that it prompted for the password of the remote server, but after i typed the password, the bash just said

-bash: mypassword: command not found

I have also tried the --password-file option, but seems the --password-file is not for SSH account, it's for rsync service.

Could someone tell me how to input password automatically while keeping the nohup.

Dagang
  • 24,586
  • 26
  • 88
  • 133
  • 2
    Just set up an ssh key pair in the normal way - plenty of examples of this on http://superuser.com, where this question also belongs, since it's not programming-related. – Paul R May 21 '12 at 10:26
  • password entry doesn't work because the command is running in the background. Have u tried re-directing the password from a file? something like:nohup rsync -r @: < password_file – Nishant Sharma May 21 '12 at 10:32
  • 2
    Your question seems to be the duplicate of this one: http://stackoverflow.com/questions/3299951/how-to-pass-password-for-rsync-ssh-command – Hui Zheng May 21 '12 at 10:35

2 Answers2

2

you don't want to input a password for that kind of use case. But you can use a ssh key (ssh-keygen -f ~/.ssh/id_rsa_that_key) protected by a password, and use ssh-add ~/.ssh/id_rsa_that_key to keep that password in cache. And indeed it's not programmer related...

zmo
  • 24,463
  • 4
  • 54
  • 90
0

From the manpage:

Some modules on the remote daemon may require authentication. If so, you will receive a password prompt when you connect. You can avoid the password prompt by setting the environment variable RSYNC_PASSWORD to the password you want to use or using the --password-file option. This may be useful when scripting rsync.

WARNING: On some systems environment variables are visible to all users. On those systems using --password-file is recommended.

It seems to me that your error is because you're assigning the password into a variable and it is being interpreted as a command by your bash script.

Try to set the above environment variable, remove "mypassword" from your bash script and give it another try!

Community
  • 1
  • 1
Miguel Rentes
  • 994
  • 1
  • 10
  • 27