Set up OpenSSH on your Ubuntu Server for remote access

So, you’ve set up Ubuntu Server on your machine, but it’s kind of inconvenient to switch between your main computer and the server when you need to access the server. Now, you won’t need to always have a mouse, keyboard, and monitor set up for the server because you can access it from your main computer. Also, you can finally copy & paste commands in, instead of typing every single letter. Well, with OpenSSH and a client on your main computer, this is really easy to do!

Let’s get started!

Hopefully, you’ve already installed OpenSSH on your server if you followed my tutorial. If not, log in to your server and type “sudo apt-get install openssh-server -y” and type in your password & enter to verify your identity. Now, you are hosting a SSH server on your server, which will allow it to be accessed by other computers.

Now, you need to find out what your local IP address is, and you should write this down for later. Type the command “sudo ifconfig” (and confirm with your password). This should list your network devices. If you are connected via Ethernet, look under “eth0”, otherwise look under your WiFi device name. Write down the IP address next to “inet addr”. This is the IP you will use to connect to your server from another computer on the network.

Screenshot-Boop de doop [Running] - Oracle VM VirtualBox

Now that you know your local address, you should go onto your host computer and open your command line. For Windows, type (WIN)+R to open Run. Then type “cmd” and press enter to open Command Prompt. On OSX, open Terminal. For ChromeOS and Linux, type Cntrl+Alt+T or open Terminal.

Type: “ping” then your IP address. For example “ping”. You should get a response like this:

Screenshot 2016-04-15 at 6.39.53 AM

If you get an error such as “unknown host”, please skype or email me or do some more checks with your network.

Now that you were able to ping the server, you will need a SSH client. For Windows, I reccomend downloading PuTTY. With Mac or Linux, you can just type “ssh {username}@{ip address}”, in my case I’ll type “ssh [email protected]”. For ChromeOS/Chromebooks, you can download the Secure Shell Extension. The username and password are the same you use to log into the server on the physical machine.

With PuTTY, you set the host to your server’s local IP (or “{username}@{ip address}”) and then you will log in to the account once you hit “Open”. With Secure Shell, you can also configure the username before connecting as well as the host IP.

Screenshot 2016-04-15 at 8.40.32 PM

First, it will prompt you if you trust the server’s certificate/fingerprint. Click yes. It is your own server so you don’t need to worry about authenticity. Now, you should be connected to the server and it will prompt you for a password like it would as if you were logging on directly.

Screenshot 2016-04-15 at 8.52.00 PM

After you enter the password, the server’s terminal can be accessed and you can use any commands you would normally.

Screenshot 2016-04-15 at 8.59.36 PM

However, you may want to log into your server as root. This means you will have access to all files, and all priviledges. First, you have to set the root password by “sudo passwd root”. Then type the password two times to verify.

Screenshot 2016-04-15 at 9.13.52 PM

Now that you set the root password, you need to allow root logins in the OpenSSH config. To do this, type “sudo nano /etc/ssh/sshd_config”. nano is (in my opinion) the easiest text editor to use.

Screenshot 2016-04-15 at 9.17.31 PM

Now, the file should show up in a text editor. Use the arrow keys to go down to the line that says “PermitRootLogin” and change “without-password” to “yes”.

Screenshot 2016-04-15 at 9.28.14 PM

Press CNTRL+X to exit the editor. Press “y” and ENTER to save the file. Now type “sudo service sshd restart” to restart the server. Now you should be able to use your root user to log in via SSH (or even the local terminal)

You can also use FileZilla or another FTP client to  access your server’s files. Just make sure you change the port from 21 to 22. Also, use the root user for all file permissions.

You can now access your server remotely! This makes it easier to install applications and control your new server!