Skip to content

Instantly share code, notes, and snippets.

@CreatorB
Last active March 13, 2024 10:32
Show Gist options
  • Save CreatorB/e05aa244bdaad729f98f to your computer and use it in GitHub Desktop.
Save CreatorB/e05aa244bdaad729f98f to your computer and use it in GitHub Desktop.
How to put scp in background
To execute any linux command in background we use nohup. But the problem with scp command is that it prompts for the password (if password authentication is used). So to make scp execute as a background process do this:
1>
$ nohup scp file_to_copy user@server:/path/to/copy/the/file > nohup.out 2>&1
if it prompts for password then enter password.
Then press ctrl + z which will temporarily suspend the command,
SCP will give output:
[1]+ Stopped scp file_to_copy user@server:/path/to/copy/the/file > nohup.out 2>&1
2>
then enter the command:
$ bg
This will start executing the command in backgroud
SCP will give output:
[1]+ scp file_to_copy user@server:/path/to/copy/the/file > nohup.out 2>&1
3>
To see what background process that is running you can type command:
$ jobs
SCP will give output:
[1]+ Running scp file_to_copy user@server:/path/to/copy/the/file > nohup.out 2>&1
To bring the process back to foreground you can use 'fg' command.
@Nottt
Copy link

Nottt commented Jul 26, 2019

You can use sshpass too.

apt install sshpass -y
nohup sshpass -p 'password' scp arguments

@ndrarora
Copy link

Thank CreatorB, found exactly what I was looking for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment