SSH
SSH (Secure SHell), is a protocol used mainly in Unix-based OSs to control systems remotely using an encrypted secure connection. It lets you run commands on another system as if you were in front of it.
It was first developed in 1995 by Tatu Ylönen after he discovered there was a password sniffer being used at his university, because in those times people still used non-encrypted remote access protocols like Telnet or RLogin. Back in the 90's it may have not been that important still, because of the early days of the internet and remote access not being as used as today, sysadmins would typically work in the same building as the servers are in, but in this modern age you can imagine how dangerous would be to send the admin login credentials of a server containing a full clients' database as plain text from the home of a remote worker. Encrypted remote access is a must.
The first version of the protocol "SSH-1" had vulnerabilities, so Tatu and his team developed SSH-2 which became the de facto standard for secure remote access. The developing has continued over the years and is still ongoing.
In 1999 OpenSSH was created, it's the open source implementation of the SSH protocol, implementation meaning a software you can use to execute that protocol, remember a protocol is just a set of rules. It is now widely used around the world and maintained by the OpenBSD project.
It probably comes in your Linux distro and its what you have been already using it when you ssh
in the terminal.
Even though OpenSSH is installed in almost all distros, don't panic, the server daemon is usually disabled and requires root. You can connect to remote servers but nobody could connect to you unless configured so.
Authorized_keys file: once connected to a server, you can copy your public key into the file authorized_keys
inside the .ssh/
directory to connect without password. If you need multiple, each public key has to be in its own line. If you have a matching private key stored in your .ssh/
directory, the ssh server will automatically log you in.
If you established a password on the private key it will ask you for it before being able to login, this gives another level of security and gains us time if the private key is stolen.
Known hosts: once you connect to a server it will ask if you trust the fingerprint(hashed value that uniquely identifies the server), if you accept, the server's fingerprint and public key will be stored at your ~/.ssh/known_hosts
file as:
|n|hashed-username|hashed-IP-or-hostname|algorithm-used|public-key
next time it won't ask again, as it implies the server is to be trusted.
If you connect regularly to a server and suddenly it asks you again if you trust the fingerprint (and the known_hosts files is OK) suspect a man-in-the-middle attack, if the alert prompts it indicates that the server is not in the known list so it may be a rogue server.
Log files: register each connection and when/where it came from, for Debian-based its usually at /var/log/auth.log
and Red Hat-based at /var/log/secure
Key pair: the RSA keys generated with ssh-keygen
are exclusive for ssh connections, meaning they are not compatible or interchangeable with other key pairs as for example the ones used on TLS or PGP.
Permissions: if the ~/.ssh
directory has too much flexible permissions like o+rwx
you will not be able to connect via key, as ssh considers that folder and therefore its keys insecure. It will prompt you for the password even if specifying the -i
argument.
The ~/.ssh
directory should only be accessible by you and only you.
To save connections as alias, you can create a config file "touch ~/.ssh/config"
and use the following structure to add as many as you want:
Host serverName
Hostname IP
Port 22
User Username
Now you can use "ssh serverName" and it will redirect to that connection.
Recommended video guide on OpenSSH link.
Last updated