How to Set Up and Enable SSH on Ubuntu

Setting Up 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.

Setting Up SSH

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:


Enable SSH in Ubuntu

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.


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

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.

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.

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

Generating Your Keys

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.

After making the folder, change its permissions.

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.


Connecting Over LAN

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.

Connecting to SSH Server Over the Internet

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!

Derrik Diener Derrik Diener

Derrik Diener is a freelance technology blogger.


  1. SSH has been an interest for some time, looking forward to experimenting with input from this post and learning much more … thank you very much

  2. I tried the above on ubuntu 15.10

    But can’t connect from a mac osx client:
    The command prompt on the mac says “sshd re-exec requires execution with an absolute path”

    I tried looking at ubuntu’s site, the forums do mention the problem, but the solutions posted only make sense to experienced users, not nubies like me.

    I do like your intstructions on this page, easy enough for me to follow. Just can’t figure out where I went astray.

  3. Finally understood why the error occured: On the client I entered sshd instead of ssh.

    Sorry for this nuby problem. Your tutorial works great, many thanks.

  4. Hi, thanks for this but, why are you creating ssh keys if your not using them after? You never registered the generated key on the server nor used to log in to the ssh server. Any reason for this?


Comments are closed.