0 - Introduction
If you use your ubuntu machine to host a server, website, or if you just need to keep tabs on it’s use without being face to face with it you might be wondering how you could do that, gladly ssh exists and it is very simple to setup!
When you get a problem installing or updating something it is possible that the reason it is happening is because your system is outdated, so we recommend updating it before starting this tutorial. Updating is very easy and you only need two commands:
sudo apt update
sudo apt upgrade
1 - Install OpenSSH server
To install openssh-server you really just need a terminal and to know the root password. And if you are happy with the default configuration, you are done with only this one command:
sudo apt install openssh-server
At this point you can already connect to your machine with the following command and everything after this is optional.
ssh username@machineip
2 - Change configurations (optional)
Before changing anything we recommend you make a copy of the original configuration, so if you make a mistake and don’t know how to fix it, you can just restore the original config. To make a backup of the original config you only need two commands, the first that makes a copy of the configuration file and the second that removes the write permission to the file, so that you don’t change it by mistake.
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.original
sudo chmod a-w /etc/ssh/sshd_config.original
If you have made a backup, or have confidence in yourself, you can edit the config with the folllowing command. You can also use any other text editor if you prefer, it just needs to be able to edit files in a protected folder (with sudo):
sudo nano /etc/ssh/sshd_config
If you are 100% sure your config is correct and ready, you can now restart the service to apply your settings with this command:
sudo systemctl restart sshd.service
# if you get an error try this one
sudo systemctl restart ssh.service
3 - Access without password (optional but recommended)
Attention: this part of the tutorial will be made in the pc you want to use to connect to the server!!
If you are tired of writing your password every time you log in to the ssh server, you have an alternative that is way more secure, using ssh keys. You can generate keys that use the RSA Algorithm with the following command:
ssh-keygen -t rsa -b 4096
You don’t need to change anything in the process, just press ENTER and skip every step until the files are generated. Now you need to add your keys to the remote machine, and you do that by running:
ssh-copy-id username@machineip
And thats it, now you have SSH working! You can connect at any time with:
ssh username@machineip
Thanks for reading! Stay tuned for more tech insights and tutorials. Until next time, and keep exploring the world of tech!