SCP (stands for secure copy) is a command-line utility, available for both the Linux terminal and Windows powershell, that allows you to securely transfer files between two SSH-enabled devices. In this example, we use SCP to transfer both a file and directory from my Windows 10 desktop to my Ubuntu Shell™.
1. First, make sure you are working in the directory that of the file/directory that you'd like to transfer. For this example, I'll be working in my ~/Documents folder. Use cd to navigate into your specified directory like so:
2. In this example, I've named a file, test.txt, that I will transfer through SCP into my Shell™. Once you have the file that you'd like to transfer, input the following command:
scp -P *portnumber* *filepath* *username*@*ipAddress*:*filepath*
where the port number is the SSH port of your Shell™. Here's what an example command might look like:
scp -P 10123 ./test.txt randomUser@22.214.171.124:~
3. If you haven't configured SSH through RSA key authentication, you will be asked for a password similar to if you were to SSH normally. Go ahead and input the password of the account of your shell, and, if done correctly, your file should begin transferring.
If you are transferring a file and would like to rename it, you can input the command as follows:
scp -P *portnumber* ./test.txt randomUser@126.96.36.199:~/test.txt2
This will, however, overwrite any other file named test.txt2 without warning. Be careful!
4. You can also use SCP to transfer whole directories as well. You can accomplish this with the option -r. An example of it being used can be seen below:
scp -P 10123 -r ./someDirectory/ randomUser@188.8.131.52:~
This will copy the contents of someDirectory into the home directory of randomUser. Pretty neat!
5. SCP is very useful if you would like to securely transfer a generated RSA public key to a host server. The command would look similar to:
scp -P 10123 ./.ssh/id_rsa.pub userName@184.108.40.206:~/.ssh/authorized_keys