Part 1: Secure Shell (SSH)
Secure Shell, sometimes referred to as Secure Socket Shell, is a protocol which allows you to connect securely to another computer or server from a command line. To use SSH, you will need to install an SSH client on the computer you connect from, and an SSH server on the computer you connect to. The most popular Linux SSH client and Linux SSH server are maintained by the OpenSSH project. The OpenSSH client is included in Ubuntu by default. The OpenSSH server can be installed on the remote machine by running this command on that machine.
In this tutorial we are going to go through the steps of connecting from a linux machine to another linux machine on the same network.
The first thing we need to do is figure out the ip address of the remote machine. Open a terminal on your remote machine and run the following command.
You should see something like this.
In this example I’m connecting from a laptop to an HP Mini notebook. The username on the remote machine is blackmini. So I will connect by running the following command. (Obviously you would type the username and host that applies to your network.)
The first time you connect to a new machine, you will see something like this…
The authenticity of host '192.168.0.34 (192.168.0.34)' can't be established.
ECDSA key fingerprint is SHA256:cXCey/JaNo5698j03TglurVZ1s5FCwY1wn+tTalMP3o.
Are you sure you want to continue connecting (yes/no)?
Type yes and press the Enter key.
Then you will see the following message.
Warning: Permanently added '192.168.0.34' (ECDSA) to the list of known hosts.
And you will see a login prompt asking for the remote machine’s password.
blackmini@192.168.0.34's password:
Type the password and press the Enter key. Congrats! You’ve successfully connected to the remote machine via SSH! You can disconnect from the machine by running the exit command. Now that you’ve connected once, you won’t get the key fingerprint message anymore. Instead you will be taken directly to the password prompt. Could it be any easier?
Yes. Yes it could.
Imagine if you could connect securely without the password prompt. Not only would that be easier and faster, but with no password prompt you could run an automatic script to edit things on the remote machine or transfer things back and forth.
Now stop imagining and make it happen. Run this command on the client machine and it will generate a public key.
You will be asked 3 questions. You can just press the Enter key for each one and then it will give you some confirmation info and show you the key’s randomart image.
Enter file in which to save the key (/home/sudofry/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Next, copy that key to the remote machine with the command below. This will be the last time you have to enter the password. Start getting excited.
You’re all set up! Now whenever you run the command to connect, the client key will be compared to the server key to see if they match, then you will be instantly logged in. Go ahead. Try it.
The last thing we are going to go over before moving on to the second part of this tutorial is X11 forwarding. When you connect with the command below, you will be able to graphically run programs from the remote machine on your client.
Part 2: Secure Copy
You can use secure copy (scp) to move things around between machines in much the same way that you would use copy (cp) to shift files and folders around on one machine. If there is a space in any of the paths, don’t forget to put double quotes around the full path. Run the following commands on the client.
Copy a file from your desktop to the remote machine’s desktop.
Copy a file from the remote machine’s desktop to your desktop.
Copy a directory from your desktop to the remote machine’s desktop.
Copy a directory from the remote machine’s desktop to your desktop.
If you connect to a remote host on a different network that uses a router port other than the standard port 22, you can specify the port like this. Replace XXXX with the port number.