scp as a background process

To execute any linux command in background we use nohup as follows:

$ nohup SOME_COMMAND &

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:

$ nohup scp file_to_copy user@server:/path/to/copy/the/file > nohup.out 2>&1

Then press ctrl + z which will temporarily suspend the command, then enter the command:

$ bg

This will start executing the command in backgroud

About these ads

23 thoughts on “scp as a background process

  1. Pingback: Buzz Lightyear is here » Blog Archive » links for 2010-12-30

  2. Hi man,

    I’d like to thank you for your greate help regarding scp with password authentication vs. background copying!!

    Viktor

  3. @c: After you enter the command it should ask you for password.
    For eg:

    $ nohup scp file_to_copy user@server:/path/to/copy/the/file > nohup.out 2>&1

    After this command it should prompt you for password.

  4. Pingback: scp as a background process | Gimli's Nipple

  5. If you have more that one job running you can run jobs to see the status

    $ jobs
    $ %job_number_1
    $ %job_number_2
    $ %job_number_3
    $ %job_number_4

    You can run bg %job_number or fg %job_number to swap jobs to the background or foreground

    $ bg %job_number

  6. another variant is the use of the ‘screen’ command:

    $ screen scp file_to_copy user@server:/path/to/copy/the/file

    after that screen opens a new terminal, with a new shell & the command excecuted. now you should press:

    ctrl + a

    and after that you can press

    d

    to detatch the screen session. the session will resists in the background and you can logout. the main advantage of this kind of backgrounding is, that you can reconnect to the session anytime with a:

    $ screen -r

    hope this helps someone ;)

  7. another variant is the use of the ‘screen’ command:

    $ screen scp file_to_copy user@server:/path/to/copy/the/file

    after that screen opens a new terminal, with a new shell & the command excecuted. now you should press:

    ctrl + a

    and after that you should press

    d

    to detatch the screen session. the session will resists in the background and you can logout. the main advantage of this kind of backgrounding is, that you can reconnect to the session anytime with:

    $ screen -r

    hope this helps someone ;)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s