6

I have a LINUX machine (remote), and a MAC machine (local). Our system administrator set up an "SSH" method, whereby I can ssh from my MAC, to my LINUX machine, via this command on my MAC:

ssh marcus@gateway.highlabs.co -p 12345

When I do this, I am prompted to put in the password for my LINUX machine, and when I do, I have access, which is great.

What I want to do now though, is be able to scp from my MAC machine, to my LINUX machine, so that I can transfer files over. How do I do that? I have googled around but I am not sure what to do.

Thank you

marked as duplicate by heemayl, Anthony Geoghegan, Jeff Schaller, imz -- Ivan Zakharyaschev, Jesse_b Dec 31 '17 at 1:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

10

To copy from REMOTE to LOCAL:

scp -P 12345 user@server:/path/to/remote/file /path/to/local/file

To copy from LOCAL to REMOTE:

scp  -P 12345 /path/to/local/file user@server:/path/to/remote/file

Note: The switch to specify port for scp is -P instead of -p

If you want to copy all files in a directory you can use wildcards like below:

scp -P 12345 user@server:/path/to/remote/dir/* /path/to/local/dir/

or even

scp -P 12345 user@server:/path/to/remote/dir/*.txt /path/to/local/dir/
  • What is "user@server" here though? – TheGrapeBeyond Dec 30 '17 at 19:35
  • user = username . server = hostname or IP address. From your mac it would be marcus@gateway.highlabs.co but if you ssh into the linux machine and wanted to copy something back to your mac, you would need to use your mac username/hostname. – Jesse_b Dec 30 '17 at 19:42
  • Hi Jesse, yes I guess what I dont understand is what the "server" should be since I do not know the IP of the remote... – TheGrapeBeyond Dec 30 '17 at 19:44
  • if gateway.highlabs.co is the remote machine then gateway.highlabs.co is the hostname/FQDN...or at least is aliased/in your /etc/hosts. – Jesse_b Dec 30 '17 at 19:46
  • Oh I see what you mean - I think this worked! I just had to put the -P 12345 right after the scp command though. :D One last q: How would I move a bunch of files altogether at the same time with one scp command? Thank you so much you saved my Saturday!! :D – TheGrapeBeyond Dec 30 '17 at 19:49
4

You should use something like this

scp -P 12345 -p some_file marcus@gateway.highlabs.co:

This will copy some_file to your home directory on the remote server. Change the name or path by putting the alternative immediately after the : (no space). Swap the arguments to copy back to the local system.

The -P 12345 is equivalent to your -p 12345 and the -p flag tells scp to maintain the timestamps and permissions for the destination file.

  • Thanks, I am trying to reconcile what you wrote with that @Jesse_b wrote - I would like to copy a file from my mac to the remote, and vice-versa.. – TheGrapeBeyond Dec 30 '17 at 19:40
  • Ok I think I got it to work... however it keeps asking me for my password everytime I run the command - how do I make it so I just need to enter the password once? Thanks!! – TheGrapeBeyond Dec 30 '17 at 19:43
  • @TheGrapeBeyond the command uses the ssh transport to log you in each time you copy a file. Search (on the this site, amongst other places) for "password-less logins" and "ssh certificates". – roaima Dec 30 '17 at 20:15
3

If you are doing this frequently I would suggest adding some config in the file ~/.ssh/config

add the following lines

Host highlabs
   Hostname gateway.highlabs.co
   User marcus
   Port 12345

Then you can

ssh highlabs

or

scp highlabs:/path/to/file /local/path/to/file

to copy from the server

or

scp /local/path/to/file highlabs:/remote/path/to/file

to copy to the server

If you are using key auth tab completion works the whole way, For example ssh hi<tab> will finish off the word and scp highlabs:/et<tab> will expand to /etc after checking the files on the remote server

  • Thanks. This is a life saver. – Omar Tariq May 6 at 6:55

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