I want to copy a file via ssh when I've logged in. What scp does is that it copies the files by login, password, path. What I want is to be able to do the same thing when I'm "inside", ideally without providing the login and password:

$ ssh root@
root's password:

Welcome to .....
Last login: ....
root@folder1:~# // How do I download (or upload) the files when I'm here?

2 Answers 2


As pointed out in this Ask Ubuntu answer, you may use zssh instead of ssh. When using zssh, you'll be able to switch to file transfer mode using Ctrl + @. This should allow you to transfer files back and forth between the local and remote ends of your active connection.

Another trick pointed out in that answer is to send ssh to the background while you call scp. This may require re-authentication though, but if you setup passkey authentication, this shouldn't be a problem. To send ssh to the background, hit Ctrl + Z. You should then be able to call scp, and get ssh back when you're done, using fg.

Edit: as pointed out by muru, in order to handle Ctrl + Z locally, and not remotely, you'll have to use Enter, ~, Ctrl + Z. See about SSH escape sequences.

Basically, scp and ssh just don't work the same way. You'll need a trick to make one do the other's job. Some of those tricks are given in the question I linked earlier.

  • Is sending ssh to the background shell dependent? I couldn't do it on zsh with Ctrl-Z.
    – muru
    Dec 9, 2014 at 8:33
  • @muru This is handled by the terminal, but requires a little bit more setup (see the Ask Ubuntu answer) ; otherwise, the Ctrl+Z sequence is handled remotely. I'll edit my answer. Dec 9, 2014 at 8:35
  • Ah, so this is through Enter-~.
    – muru
    Dec 9, 2014 at 8:36

If you set up a control file, you can reuse the existing connection authentication. From man ssh_config:

         Enables the sharing of multiple sessions over a single network
         connection.  When set to “yes”, ssh(1) will listen for
         connections on a control socket specified using the ControlPath
         argument.  Additional sessions can connect to this socket using
         the same ControlPath with ControlMaster set to “no” (the
         default). ...
         Two additional options allow for opportunistic multiplexing: try
         to use a master connection but fall back to creating a new one if
         one does not already exist.  These options are: “auto” and
         “autoask”.  The latter requires confirmation like the “ask”

So, if you connect using the options -o ControlMaster=auto -o ControlPath=/tmp/ssh-%h-%r, the first connection can be reused for scp. This can be set in your ~/.ssh/config:

Host some-host
  ControlMaster auto

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