How to Set Up and Enable SSH on Ubuntu

If you’ve been using Linux for any amount of time, you no doubt have heard about a tool known as SSH. SSH (or secure shell) is an encrypted networking tool designed to allow users to log in securely to various different types of computers remotely over a network. In this article, we will show you here how to set up and enable SSH on Ubuntu.

To get started, we have to install the SSH server. You can find and install the openssh-server package in Software Center. Alternatively, open a terminal and type the following command:

sudo apt-get install openssh-server


Once OpenSSH server has been installed on your machine, you’ll need to make a copy of the default SSH configuration and rename it as factory default. This is so if you mess up your configuration tweaks, you’ll be able to restore the backup.

sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.factory-defaults


After the backup has been made, you’ll need to modify its permissions.

sudo chmod a-w /etc/ssh/sshd_config.factory-defaults

After the backup is taken care of, you’ll be able to configure your SSH file.

Note: only tweak this configuration file if you know what you are doing. Beginner users shouldn’t need to tweak anything for SSH to work.

sudo gedit /etc/ssh/sshd_config

When all of the changes have been made, you’ll need to restart the SSH service. If you’re using Ubuntu 14.04, you’ll need to rely on Upstart to reboot the SSH server.

sudo restart ssh

If you’re on Ubuntu 15.04+, use this systemd command to restart SSH instead.

sudo systemctl restart ssh

SSH Keys are very important. Without them you won’t be able to connect to your server. To start making your keys, create the folder in which your newly-generated key will live.

mkdir ~/.ssh

After making the folder, change its permissions.

chmod 700 ~/.ssh

Finally, generate your key. Keep in mind that SSH is only as safe as the password you set up. If you enter a weak password, one that can be guessed easily, you’ll be open to attacks. Instead, try to generate a secure, memorable password.


ssh-keygen -t rsa

Want to connect over LAN? It’s easy! Just open a terminal window and figure out the IP address of the machine with the SSH server running. This can be done simply by running the ifconfig command.

Once you’ve determined the IP address of the machine, you’ll be able to log in. Just go back to the machine you’re trying to log in with and enter this command:


Note: change the “username” to the user name of the SSH server.


From there you’ll be prompted to enter your password. Do so. Soon after you’ll be logged in over LAN via SSH.

Along with connecting over LAN, connecting via SSH over the Internet is possible too. It just requires a bit of network savvy to set up. If you want to do this, you’ll need to set up port forwarding for your router.

Since every router out there is vastly different, you’ll need to do your own research on this topic. Just make sure you forward port 22 to the Internet from whatever machine is set up to use the SSH server, and you’ll be set.


After setting up port forwarding, you’ll need to determine the IP address of the machine you’re trying to SSH to. The easiest way to figure this out is to head over to They’ll tell you your Internet IP address.

Once you’ve gotten your Internet IP address, you’ll be able to log in. Just go to your terminal and enter the following:


From there you’ll be prompted to enter the SSH password. Enter it, and soon after you’ll be logged into your machine over the Internet via SSH.

Congratulations, you have completed setting up SSH in Ubuntu; you can now proceed to secure your SSH server.

SSH is a powerful and versatile tool. With it you can do just about anything, such as remote system management, moving files around, even just running programs from one computer to another. I hope that with this guide you, too, will discover just how much you can do with this simple tool.

How do you feel about SSH? Tell us in the comment section below!