How to copy files on your LAN via SSH

SSH (Secure SHell) is the name of a protocol used to access remote machines over a network. It allows fully control the computer using a command interpreter. Further, SSH allows us to copy data safely (information travels encrypted). So, if you have Linux on both machines and you want to copy data without installing SAMBA, be sure to try this option. You can use it direct from Nautilus!

Using Nautilus

1. Install openssh-server on the computer you want to connect from. Actually, if we assume that at some point we'll want to connect from the other computer to the one we're currently using, it would make sense to install openssh-server on both (or more) machines.

sudo apt-get install openssh-server

2. You can restart the computers or run openssh-server.

3. On the machine from which you will control the entire operation, open Nautilus and press Ctrl+L to type in the address bar. Type ssh://NROIP. The first time you connect to that computer, you will see a message saying that host authentication cannot be performed. Select the option to proceed.

4.- It will ask you for the username and password you want to use to log in to the machine you want to access.

5. Let's set sail! 

From the terminal

1. On the computer from which you will control the entire operation, type:

ssh NRO_IP

2. It will ask for the password and then you will be able to access all the files on the remote computer.

3. To log out, press Ctrl+D (if you have Bash) or type:

logout
In case, after connecting successfully several times, it suddenly refuses to connect. Try deleting the list of known hosts, executing the following command on the computer you want to access from: rm ~ / .ssh / known_hosts.

Using SCP

SCP is an SSH plugin that allows us to copy files quickly and safely.

The syntax is very simple:

scp file user @ server: path
Note: In case you get the error "ssh: Could not resolve hostname earendil-desktop: Name or service not known lost connection", try replacing server with the server's IP number. Thanks to Snocks, we know that it is also possible to add a line, in the format "IP hostname", to the file / Etc / hosts. Ex: 192.168.1.101 earendil-desktop.

To copy in reverse, from the remote computer to yours, I simply reversed the order:

scp user @ server: path / file local_path

That is, for example, if we wanted to send something to the remote computer:

scp list.txt earendil @ earendil-desktop: ~ / miscosas

This command copies the file list.txt from the computer I am using to the ~ / miscosas folder on my remote computer. The owner of this file will be the earendil user (of my remote computer).

To copy entire folders, just add the -r parameter:

scp -r ~ / earendil photos @ earendil-desktop: ~ / miscosas

This command copies the photos folder, located in the HOME of the computer that I am using, to the mythings folder, which is located in the HOME of my remote computer.

Now, the same process in reverse would be:

scp earendil @ earendil-desktop: ~ / my stuff / photos ~

This would copy the ~ / my stuff / photos / folder from the remote computer to the HOME folder on the computer I'm using.

Finally, it is important to note that the default path is your user folder. If you want to copy something to or from there, you can omit the path:

scp list.txt earendil-desktop:

In this case, as the user is repeated on both machines, it is not necessary to type it. Also, I am copying from HOME to HOME, which is why it is not necessary to type the full path of the files either.


Add as preferred source in Google