I often have the requirement to run an SCP in the background (i.e. not terminally attached) on servers that have not exchanged keys to facilitate password less access. Hence, there is a need to provide a password in the foreground.
To put the SCP into background, enter the SCP command as follows (No “&” at end):
nohup scp -p /source_directory/my_very_large_file.bus myuser@target_server.somedomain.com:/target_directory > nohup.out 2>&1
You will be prompted for the password:
[unix_prompt] nohup scp -p /source_directory/my_very_large_file.bus myuser@target_server.somedomain.com:/target_directory > nohup.out 2>&1 myuser@target_server.somedomain.com's password:
Enter the password and press enter
Then press CTRL Z
Output will look like this. You can see the CTRL Z and a message that states it is stopped:
[unix_prompt] nohup scp -p /source_directory/my_very_large_file.bus myuser@target_server.somedomain.com:/target_directory > nohup.out 2>&1 myuser@target_server.somedomain.com's password: ^Z [8]+ Stopped nohup scp -p /source_directory/my_very_large_file.bus myuser@target_server.somedomain.com:/target_directory > nohup.out 2>&1
After you see the stopped message and are back at the prompt type in “bg”:
[unix_prompt] bg [8]+ nohup scp -p /source_directory/my_very_large_file.bus myuser@target_server.somedomain.com:/target_directory > nohup.out 2>&1 & [unix_prompt]
The SCP will now be resumed in background:
[unix_prompt] ps -ef | grep myuser@target_server oracle 42065 54077 1 18:16 pts/2 00:00:02 scp -p /source_directory/my_very_large_file.bus myuser@target_server.somedomain.com:/target_directory oracle 55618 54077 0 18:18 pts/2 00:00:00 grep myuser@target_server
The SCP is now running in the background and the terminal is freed.