How To Enable SSH on Linux

November 28, 2020
November 27, 2020
a screenshot of the Synaptic Package manager dialog showing results for the search term 'openssh' Linux shines in the command line. As a Windows user, I always appreciated the GUI, as shown by my emphasis on DeskThemePacks. There is more flexibility and versatility when you use the command line interface on either, including the ability to roll tasks together or create unique instructions. Secure shell (SSH) is a way for a user to remotely, and safely (if configured correctly), administer their Linux workstation. You could run mainteance tasks, write documents, install and update programs, to name a few actions. This tutorial will be split into two sections: "Layman", which is how to get it running, and "Foreman", which digs into the more secure preferences. If you plan to use this over a remote address, please read the "Foreman" section as well.
First, you'll need to make sure "OpenSSH" is installed on the machine. Not every Linux package is a graphcial program - some of it compliments or adds functionality to the system's existing app suite. If you don't need a feature, you can typically live without its package. The ability to connect with SSH FROM your PC is installed by default in Linux Mint Ulyana and Debian Edition 4. However, you'll need to install the component that alllows users to connect TO you as well. Open your mint menu, type "Synaptic P" and select the resulting program from the list, which resembles a teal square with white arrows pointing in opposite directions. Enter your privileged password.
a screenshot the samba share password prompt On the top right portion of the window, enter "openssh" as a search query using the "Description and Name" modifier and press "Search". Once you do, scroll down until you see packages that start with "o". If my earlier remarks are valid for your installation, you'll see a green square (meaning it's already installed) for "openssh-client" but NOT for "openssh-server". "openssh-server" is the one we want to install. Click its nearby square, and select the option "Mark for Installation". Synaptic will also install its dependencies for you (if any exist). During my installation, at least six dependencies were missing. Consent to these and select "Mark". Then on the top left portion of the window, click "Apply". Review the summary, and then click "Apply". Cold feet? You can check "download package files only" and resume this tutorial at another time.
Still here? Let's go on. Assuming you did install the server end, you'll need to enable port 22 in the Linux Firewall on both ends so that the computers can talk to each other. This tutorial assumes you're not doing this from a remote address and that you have two Linux machines on the same local network. Open the mint menu, type "Firewall" and then select the result, which should be an icon that resembles a brick wall. Enter your privileged password when prompted. When you do, the Firewall home page will appear. Press the "+" icon on the bottom left side of the window. Then, click the "Simple" tab on the next window that appears and enter "Both" for "Direction" and "Protocol", "Allow" for "Policy", and "22" for "Port". The description is optional and not needed, but can help sift through a list of rules better.
a screenshot of the Linux Firewall start page a screenshot the Add Firewall Rule simple dialog showing port 22 Foreman These instructions are for users who would prefer a more secure, paranoia-friendly setup. I followed these instructions in my setup and if you do care about access control, so should you. Otherwise you're welcome to stop reading. There's a config file on the system that allows you to specify how SSH connections are handled on this PC. If you plan to have these PCs talk to each other, you will need to make sure those settings are the same on both PCs so that it does not affect your ability to connect.
Open your terminal, and type the following command:
sudo xed /etc/ssh/sshd_config
A text editor will appear with a red banner indicating you're editing a file with root privileges. To change the default port, navigate to line 15 and remove the hash sign next to it. You can enter any unprivileged port above 1023 you like that isn't already in use. If there are other parameters you would like to enable, scroll down the document and remove the hash sign next to each one you want to activate. Save and close when you're done. Also, type this command in the terminal:
sudo service ssh restart
This will cause the service to restart, which will put the settings you enabled into effect. To utilize access control on this PC for SSH and other resources, you'll need to make modifications to /etc/hosts.allow, which specifies which hosts can connect, and /etc/hosts.deny, which excludes connections. Entries in hosts.allow supersede entries in hosts.deny. Open a terminal and enter the following command(s), depending on which file you need to edit:
sudo xed /etc/hosts.deny Pick this file if you would like to start banning everything at first. This is the most secure, but most inconvenient option. The syntax for entries is:
protocol_type : ip_address_or_dns_domain, wildcard_type
More information
Using ALL : ALL is the surefire way to start from restricting everyone. But of course, you'll need to allow some users. To allow a user on the local network you trust, you'll need to find out their private IP address. On a Linux machine, you can type hosts in a terminal window and use the "inet" value. Use this value and add it to hosts.allow. For example, if I wanted to allow and I was on, I would write sshd :, LOCAL in the next available line, save the file and restart the ssh service. DNS Domains are compatible (like sccc.sunysccc.local, LOCAL) with the allow and deny lists. If it's a local resolver, you should include the LOCAL wildcard.
Now that you've read both tutorials, it's time to start a session! Open your terminal or a new tab with CTRL+SHIFT+T and type the following (substitute #### for the port number you specified in /etc/ssh/sshd_config) and press enter:
ssh username@device_private_ip -p####
a screenshot of the ssh prompt asking the user to enter a remote password a screenshot of that same ssh window showing a successful login and remote access to another computer's terminal If it's your first time communicating, you will be asked whether or not to confirm you want to connect. If you're sure, type yes. Then, type the password of the account you named in the ssh command, NOT the one you're logged into this computer with. Then press Enter. Your cursor will change from localuser@thismachine to remoteuser@othermachine, and you'll be able to run commands as if you were logged in. To test my success, I created a text document on my REMOTE desktop:
echo -e I figured out SSH"\r"Yay me! > ~/Desktop/ssh_success.txt
I reccommend that you set up SSH keypairs between the devices you're connecting with. Once you have, your ability to connect will be more straightforward, and you won't need a password. This step was done between a DigitalOcean droplet and a Linux Mint 20 installation. If you haven't already, create an SSH key in terminal using the following command - OpenSSH should be installed:
You will then be asked where you want to save it. The default filename is fine, but if you're paranoid, I'd change it. But you would have to edit the sshd_config file to reflect this. I strongly recommend a passphrase. It should differ from your user account password and will be needed in the next step. Now, log in to your droplet using SSH. Type nano ~/.ssh/authorized_keys and paste the contents of your public SSH key, located in ~/.ssh/ on the CLIENT, and add this as a single line to the authorized_keys file on the SERVER. Then click Save.
Log out of your droplet or server. Then log back in. You will see a prompt asking for the passphrase of your SSH key. If you use a password manager, make sure it's in the clipboard before you attempt to log on, because Linux will erect a Secure Desktop scenario where no other app can be clicked except the prompt. Paste it, click "Remember this password" if you'd like, and then click "OK". Now you will no longer need the password. As it stands, the default behavior for refusing to enter the private passphrase is a fallback to Unix authentication. To disable this, open /etc/ssh/sshd_config, navigate to Line 56, uncomment it, and type "no" in place of yes. Clear text tunneled passwords will be turned off. I have verified that this method works.
Do not forget to restart ssh on BOTH sides by typing the following command in terminal - if you are not running root interactively, then you must enter your privileged password if asked in the secure dialog prompt:
systemctl restart ssh
- 🎙
© 2020 Mass Transit Honchkrow