Skip to content

Instantly share code, notes, and snippets.

@tommyskott
Last active December 16, 2021 08:49
Show Gist options
  • Save tommyskott/04e621fc4f6a8a46b98da92e3112f093 to your computer and use it in GitHub Desktop.
Save tommyskott/04e621fc4f6a8a46b98da92e3112f093 to your computer and use it in GitHub Desktop.
SCP - Cheat Sheet

SCP - secure copy protocol

Transfer files from unix machines.

In this example, we have setup the credentials for our remote server with the alias of xwing. This allows us to connect to the server without having to type all the credentials every time.

You just simply connect by typing: ssh xwing

We don't need to login before we run the scp command, so let's logout and setup the ssh config.

Type exit to logout.

Add our VPS to our SSH config

You can open this file with your favorite editor, just type code, atom or sublime instead of nano.

nano ~/.ssh/config
Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa
  
Host xwing
  Hostname insert_ip_address
  User insert_username
  IdentityFile ~/.ssh/your_key_file_here.pem

If you haven't setup your ssh-keys correctly before, follow this guide: SSH setup

Upload to remote

scp my-file.txt xwing:/var/www/my-project
scp -r my-folder xwing:/var/www/my-project

Download from remote

scp xwing:/var/www/my-project/my-file.txt /local/path

Transfer from remote to remote

scp xwing:/var/www/my-project/my-file.txt xwing2:/var/www/my-project-2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment