Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I took a look around at other questions here and at various "scp usage" tutorials on Internet, but I can't sort out what's wrong.

I'm using Linux Mint and I'm trying to figure out how scp works.

I've a file file.ext (on my computer) in directory /home/name/dir/

I connect to a remote machine using ssh, like:

ssh -p 2222 username@domain

it asks me the password and the shell displays:

username@domain ~ $

now, If I issue the command (before I ran ssh I was in the local directory /home/name/dir ):

scp -r -P 2222 file.ext username@domain 

output is:

cp: cannot stat ‘file.ext’: No such file or directory

Same result if instead of file.ext I write the complete path

scp -r -P 2222 /home/name/dir/file.ext username@domain 

Also, the server admin told me that I shall upload the file to my remote home directory (instead of root), like:

scp -r -P 2222 file.ext username@domain:~/

but when I do it and press "Enter" nothing happens, as If the shell was waiting for further input.

Summary of my problems:

  • cp: no such file or directory
  • shell "stuck" on ~/

Any suggestions?

share|improve this question
it's slightly unclear whether your problem is only related to being on the wrong machine...could you please prefix each command with the host you are running on? e.g. localuser@machineA: ssh -p 2222 username@domain (to indicate that you are running the ssh command as localuser on machineA) – umläute Feb 17 '14 at 16:09
when using scp, the remote side always has to contain the colon (e.g. remotehost:/tmp), else it will just do an ordinary copy (scp /tmp/foo.txt example.com will copy /tmp/foo.txt into a local file example.com) – umläute Feb 17 '14 at 16:11
remove the -r flag, as this is not needed for copying single files (it's used to recursively copy directories) – umläute Feb 17 '14 at 16:12
Are you issuing the scp command inside the sshe session? It would make sense if you are on the local machine. – alexis Feb 17 '14 at 16:13
scp -P 2222 file.ext username@hostname-or-ip_address:/remote/path/ – Christopher Feb 17 '14 at 16:14
up vote 18 down vote accepted

You need to run the scp command from the local machine, not on the remote. You don't need the ssh at all:

dragonmnl@local $ scp -P 2222 file.ext username@domain:~/ 

You also don't need the -r:

 -r      Recursively copy entire directories.  

If you are already logged into the remote machine and want to copy from your local, you need to make sure that your local machine is accessible via the internet and has ssh set up. I don't think this is what you are after but if it is, just run this from the remote:

username@domain $ scp dragonmnl@local:/path/to/file.ext ~/
share|improve this answer
thanks. the problem was I was trying running scp inside ssh session. now it works! – dragonmnl Feb 17 '14 at 16:19

If you're running this scp command on the remote machine, it is looking for file.ext as a "local" file, i.e. on the remote machine.

To copy a file from the remote machine to the local one, use scp -P 2222 username@domain:dir/file.ext localdir (assuming that file.ext is in ~/dir on the remote computer, as in your example). If you run scp on the remote machine, reverse "local" and "remote".

share|improve this answer
The OP wants to copy from local to remote, see the OP's title. – terdon Feb 17 '14 at 16:10
Oops, I guess you're right. But he's apparently doing it backwards... – alexis Feb 17 '14 at 16:15

If you happen to be on OSX...

When I tried running it with username@local:/file_directory...

I got the following error:

ssh: local: node name or service name not known


On my Mac I had to do the following to setup local ssh:

‘System Preferences’ --> ‘Internet & Networking’ --> ‘Sharing’ --> ENABLE ‘Remote Login’

This then provided the username@ip address.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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