Green box with SSH in middle

How to create SSH Profiles!

What is SSH?

SSH stands for Secure Shell. People used to use Telnet but the traffic created by Telnet was not encrypted so they created SSH. Meaning telnet traffic can be intercepted.

SSH allows you to access a server or computer that is remote. It allows you to connect in a way that is encrypted. You can run commands and access a remote server.

Other protocols such as Secure Copy Protocol uses the SSH protocol. Secure Copy Protocol also known as SCP allows you easily transfer files back and forth in-between two computers.

SSH uses two type of keys, public and private which makes it asymmetric encryption. Your local computer, that is the computer that is being used to connect to the remote server has to keep the private key.

Th private key should be kept secure, while the public key can be shared. It is very important to keep the private key secure.

It is also recommended to protect your private key with a very secure password. This helps protect your remote server because to be able to connect to your remote sever you need the private key and the password to the key.

The public key is stored on the remote server in file named ~/.ssh/authorized_keys. The standard port that SSH uses is port 22. But this can be changed.

Creating the Keys.

You must have SSH already installed on the system. The command below will create keys with the ed25519 algorithm.

ssh-keygen -t ed25519

Now that the keys were created, you have to copy the public key to the remote server. The following command can be used.

ssh-copy-id root@remote-host

You need to know the IP and user of the remote host.

Let’s say you have multiple different servers using different keys. You can use ssh-copy-id to transfer a certain public key file to the remote server by using the -i argument.

ssh-copy-id -i ~/.ssh/id_ed25519.pub root@remote_host

You can also transfer your public key to a remote server on a non standard port using the following command with the -p argument.

ssh-copy-id -p 2222 mc@remote_host   

Connecting to the SSH server.

The user should the user on the remote server and the remote-host is the IP of the remote host.

ssh user@remote-host

Using SSH Alias.

Remembering a IP or the Host name is hard and challenging. You can use Aliases to easily connect to a host. You still will need to enter your key’s password. This config file should be stored in ~/.ssh/config.

An example of config file is:

Host Goldfish
        Port 22
        User root
        Hostname 192.168.1.33

Host wp
        Port 22
        User root
        Hostname 192.168.1.31
        IdentityFile ~/.ssh/id_rsa

Host email
        Port 22
        User root
        Hostname 192.168.1.32

Using the example above the following command can be used to easily connect to one of your Servers.

ssh wp

Check here to read a tutorial to learn how to remove server header from Apache2.