You can use SCP to download filess from your remote machine to your local. If you do not have key authentication established, you wull have to use passowrd to gein access to a file.
You can also send files to a server uing SCP
# SEND FILE TO SERVER scp -i ~/.ssh/id_rsa.pub FILENAME USER@SERVER:/home/USER/FILENAME # DOWNLOAD FILE FROM SERVER scp -i ~/.ssh/id_rsa.pub USER@SERVER:/home/USER/FILENAME /home/USER/FILENAME# RECEIVE
* Generaly, you will run this commands from your local machine (Linux / Windows – with Linux subsytem anabled) but you can also send and recive files from server it self. Just rememeber to establish authentication and edit credentails as needed.
Generate SSH .pub KEY on your local machine
The first thing that must be done is the creation of an ssh key pair. To do this, open up a terminal window and run the command:
ssh-keygen -t rsa
You will be asked to name the file (use the default name) then you will be ask to establish a pass you can use none or add a pass phase. You will be asked to pass this password every time when you try to ssh to a server (no more server password propmps after completing this setup).
Copy your public key to server using the fallowing command (you will be promped for a server password) :
Example: SCP from Windows to Linux server:
Let say we want to download a site backup from a linux server to our local machine for development setup. We could download the tar.gz file to our local dev directory. [Note this vide does not describe the proces of compresing and uncompresing files and more – if you interested in this and other usefull linux operations read at this article: Working With SSH ]
scp -i ~/.ssh/id_rsa.pub DevWL@xyz.somehost.com:/home/DevWL/domains/_sitebackup_/sitebackupname-2021-08-25-00-19_site.tar.gz "C:/laragon/www/somedir/"
Bypass typying ssh key password every time you run SCP command
If you set a password for your SSH KEY you can bypass retyping this pass on every SCP command request. Let’s say you are about to undergo a long session of copying files to your server. Sure you could tar them all up into one bigger file, but say they need to all be placed in different directories. That’s a lot of typing. You can make this slightly more efficient by using the ssh-agent and ssh-add commands. That’s right, using the combination of scp, ssh key authentication, and ssh-agent works really well. What this will do is keep you from having to type that ssh key password every time you issue the scp command. The one caveat to this is that you must remember the PID of the agent session and kill it when you’re done.
Here’s what you have to do.
- Before issuing the scp command issue eval `ssh-agent` to start the session
- Make note of the Process ID (PID) you are given when the session starts
- Add your ssh key to the session with the command ssh-add
- Start using scp to copy your files
- When you all done with your session use
kill PIDNRHERE[replace PIDNRHERE with actual PID number]