Select Page

How to setup SSH server on Ubuntu 16.04

by | 21 December 2017 | Linux | 0 comments

First of all – what is SSH?

Secure Shell (SSH) is a cryptographic network protocol for operating network services securely over an unsecured network.

Wikipedia said…

Imagine this situation: you have server at your office and you are at home. You want to do some things on the server from your home. Using SSH protocol you can have a terminal from your server on your computer at home. And finally – when you have access to the server’s terminal, you can do anything on this server from your home or other office.

So let’s start!

First install openssh server:

sudo apt-get install openssh-server

 

This should install ssh server. Next type:

sudo service ssh status

 

You should see something similar to this:

ssh_status

Status of SSH service

Now you can try to connect to this server from another computer:

ssh username@server_ip

Next type password and you are in the server’s console. Of course if you want to get this connection from the external network (for instance from your home) you have to forward port on your router. Default port for ssh service is 22. I advise changing this default port to another. In my case I use port 59184. How configure port for ssh? Simply edit file /etc/ssh/sshd_config. So use your favourite text editor or just nano in terminal:

sudo gedit /etc/ssh/sshd_config

Find line

Port 22

and change it for 59184 in my case. You can specify here multiple ports:

# for internal network
Port 22

#for external network
Port 59184

Next we have to configure firewall on our server. We need to allow connection to port 59184:

sudo ufw allow from 59184
sudo ufw enable
sudo ufw restart

We allowed for connection via port 59184, next we enabled firewall and restarted it.

 

Now from your second computer you should connect using this command:

ssh username@server_ip -p 59184

You should see asking for password and after type it you should be on the server terminal.

That’s it! Next time I write something about hardening ssh server.

Follow us