I have scp transfer (from one remote server to another), that is quite big.

So maybe I want close the computer from which I executed this command, will this end the transfer? I have ssh access to the shell using the program Bitwise.


There are a number of solutions.

Background & Disown the Process

  1. Open ssh terminal to remote server.
  2. Begin scp transfer as usual.
  3. Background the scp process (Ctrl+Z, then the command bg.)
  4. Disown the backgrounded process (disown).
  5. Terminate the session (exit) and the process will continue to run on the remote machine.

One disadvantage to this approach is that the file descriptors for stdout and stderr will still contain references to your ssh session's tty. The terminal may hang when you try to exit because of this. You can work around this by typing ~. to force close your ssh client (that escape sequence must follow a new line...see also ~?). If the process you are abandoning writes to stdout or stderr, the process may exit prematurely if the tty buffer overfills.

Create a Screen Session and Detach It

GNU Screen can be used to create a remote terminal session, which can be detached and continue to run on the server after you log out of the session. You can then log back into the server at a later date and reattach to the session.

  1. Log into the remote server over ssh.
  2. Start a screen session, screen -D -R <session_name>.
  3. Begin scp transfer as usual.
  4. Detach the screen session with Ctrl+A then d.
  5. Terminate the ssh session (exit)

To reattach to the session:

  1. Log into the remote server over ssh.
  2. Reattach to the screen session, screen -D -R <session_name>

Run the Command without Hangups

See the answer using nohup.

Use a Task Scheduler

This is the best solution if this is a periodic sort of task that you want to automate.

Use crontab, at, or batch to schedule the transfer.

| improve this answer | |
  • Hi Damien, thanks for the nice variety of answers and formatting. But I wanted some clarity on why you specified the -D -R flags starting screen. I read the man page and it didn't help me understand: -D -R Attach here and now. ... – hello_there_andy Feb 14 '17 at 21:18
  • @hello_there_andy The manual states what -DR does clearly. Basically, if you have a Screen session already running, it will reattach to it rather than creating a new session (even if a user is logged in to it via SSH – it will kick them out, which is useful if the user is hanging due to a bad network connection.) – Damien Ó Ceallaigh Feb 15 '17 at 2:56
  • 1
    Note that specifying a session name is optional. – Damien Ó Ceallaigh Feb 15 '17 at 3:02
  • Ok I think I understand, but I guess I thought (maybe wrongly) that's what screen -r <session> did... so the -DR is different to just -r in that it can kick them out? Not just reattach and fail if another user is on it. – hello_there_andy Feb 15 '17 at 3:21
  • I did some testing to be certain. -D does what -d does, except it will also close the SSH connection (log out the user) in addition to just detaching any existing Screen sessions. -r reattaches the session. -R reattaches an existing session, but will create a new session if one doesn't exist (-r would fail if there is no session to reattach to.) So, I was slightly inaccurate in my previous description. – Damien Ó Ceallaigh Feb 15 '17 at 6:20

You could use nohup(1), i.e., do something like:

nohup scp alice@source:/the/answer/of/all bob@target.example.com:/var/tmp/42 &

This will create an output of nohup.out. Then you can safely logout.

| improve this answer | |
  • The & at the end made the difference for me! Thanks! – winklerrr Feb 6 '19 at 14:26

Yes, it will be terminated. The solution to maintain terminal session alive without connectivity is the screen program:

SCREEN(1)                                                            SCREEN(1)

       screen - screen manager with VT100/ANSI terminal emulation

       screen [ -options ] [ cmd [ args ] ]
       screen -r [[pid.]tty[.host]]
       screen -r sessionowner/[[pid.]tty[.host]]

       Screen is a full-screen window manager that multiplexes a physical ter‐
       minal between several processes (typically interactive  shells).   Each
       virtual terminal provides the functions of a DEC VT100 terminal and, in
       addition, several control functions from the ISO 6429  (ECMA  48,  ANSI
       X3.64)  and ISO 2022 standards (e.g. insert/delete line and support for
       multiple character sets).  There is a  scrollback  history  buffer  for
       each virtual terminal and a copy-and-paste mechanism that allows moving
       text regions between windows.
| improve this answer | |

As said above, you can use the screen command, for example:

  • Create screen

user@server:~$ screen -S bigscptransfer

  • You're now in the screen

ser@server:~$ scp bigfile.dat server2:.

  • Detach from the screen using CTRL+A then push D

[detached from 5899.bigscptransfer]

  • Resume session when you need it with:

user@server:~$ screen -r bigscptransfer

| improve this answer | |

nohup scp shinto@source:/home/data roose@target.example.com:/var/tmp/file

stop temporarily the command with


put on background the command, type:


yo can check the process with:


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.