Linux

How to Set Up SSH on Linux and Test Your Setup: A Beginner’s Guide

Christian Cawley Updated 21-05-2020

One of the most important ways of using Linux is via SSH. This remote access command line tool lets you do everything from installing software to configuring Linux as a web server. SSH can save time, make you more productive, and help you unlock the power of your Linux distro.

Advertisement

But how do you set up SSH, on both the client and server sides? Learn how to install and configure SSH software at both ends and remotely control your Linux computer.

What Is SSH?

SSH stands for Secure Shell and allows you to remotely control a Linux computer or server from another device. It works across local area networks and the internet, meaning that it can be used to manage a Linux-powered media server in your house, or a Linux web server on a different continent.

While SSH doesn’t give you access to the remote computer’s desktop environment, it lets you use the terminal. Once connected to the remote computer you can use it as if it was right in front of you. Just be sure to have root access.

Note that other remote access solutions are available for Linux. For example, Ubuntu users can rely on the VNC-compatible remote desktop tool Remmina Ubuntu Remote Desktop: Easy, Built-In, VNC Compatible Need to remotely connect to your Ubuntu PC? Use Ubuntu's remote desktop tools to access your PC from Linux, macOS, or Windows. Read More .

To use SSH, you’ll need to ensure that the remote computer (server) has SSH set up. Additionally, your local device (the client) will need an SSH app installing.

Advertisement

Client-Side Installation

Installing and setting up SSH on a client is simple. In some cases you don’t even need any additional software:

Connect to a device using SSH in Windows PowerShell

  • To connect to Linux over SSH from iPhone and iPad try iTerminal ($4.99)
  • If you’re using Android for SSH, try JuiceSSH (Free)

SSH not installed on your Linux system? Add by updating packages and upgrading, then installing:

Advertisement
sudo apt update && sudo apt upgrade

sudo apt install openssh-client

Used to using SSH on Windows but have switched to a Linux desktop? You might miss the PuTTY desktop SSH app with its easy mouse interface. Fortunately, it can be installed on a Linux desktop:

sudo apt install putty

With your SSH client software installed, you’re ready to set up a connection to your remote computer or server.

As a general rule for all desktop and mobile clients, all you need is an IP address or host name, and appropriate login details. While the look of the apps may differ, and the port name may need entering manually, SSH clients are mostly indistinguishable.

Server-Side Installation and Configuration

Before establishing a connection, install the server-side software to host your SSH connection. This requires someone to be present to install or enable SSH. You might already be present to do this—otherwise, a colleague or support engineer at the server end will set up SSH.

Advertisement

Note that if you’re using a web hosting package, SSH should be enabled by default. Speak to your web host to set up SSH if not.

If SSH is not enabled on the remote computer or server, install it with

sudo apt install openssh-server

Check this worked with

sudo systemctl status ssh

The command should illicit a response of “active.”

Advertisement

Check the status to confirm SSH is set up correctly

In some cases the Ubuntu firewall ufw may block SSH. To ensure this doesn’t happen, use

sudo ufw allow ssh

In some cases you’ll need to also enable SSH on the remote device. This is a security precaution that can be tweaked using

sudo systemctl enable ssh

Other options are available (stop, start, and disable) for configuring the SSH service.

Determine IP Address

To connect to the remote device over SSH, you’ll need to know the IP address of the machine. You have two easy ways to find this:

  • Run a terminal command
  • Check the router

To display the IP address of the remote system, logon and run

ip address

This will return the device’s IP address, so take a note of it. On older Linux versions ifconfig may provide better results.

You can also check your router to see connected devices. The Linux PC or server will be listed, typically by operating system or device name. This should make it simple to identify.

To display the public IP address, login to the server and open whatsmyip.org.

The IP address you use should be the one suitable for the connection. So, if the device is on the same network as the client, use the local IP address. For connections across the internet, use the public IP address. If the computer is located on a different network, make sure that port 22 is forwarded to the computer.

Connecting to Linux via SSH

Along with the correct IP address you should also have a username and password to gain access to the remote machine.

For command line SSH tools, use

ssh username@REMOTE.IP.ADDRESS.HERE

Be sure to replace username with the actual username and REMOTE.IP.ADDRESS.HERE with the remote device’s IP address. Hit Enter, and you’ll be prompted for the password.

With a correct password, you’ll get a functioning terminal prompt—you’re now logged into the remote computer.

Using a desktop SSH client like PuTTY?

Configure SSH on Windows with PuTTY

Input the Host Name or IP address, select the SSH connection type, then Open. When prompted for your username and password, enter them in the command line window to complete the connection and gain remote access.

Can’t Connect? Troubleshoot Your SSH Set Up

If you are having SSH connection issues, these are the possible causes:

  • SSH software isn’t installed on either computer
  • Your username or password is incorrect
  • The IP address is wrong
  • A firewall is blocking the connection, or port 22 is not being forwarded

Double-check each point and you should be able to connect. If not, the problem might be more complex.

Using Linux Remotely With SSH

SSH is a useful tool for managing one or more Linux computers.

It lets you can work on any machine from just one system. You can input almost any Linux terminal command 40+ Most Used Linux Terminal Commands Whether you're just getting started or simply curious about the Linux terminal, here are the most common commands that will carry you through your entire time on Linux. Read More over SSH.

Key examples include:

  • Update: sudo apt update && sudo apt upgrade
  • Check status: uptime
  • Running processes: ps
  • Running processes by CPU: top

Setup SSH on a Linux server to run commands remotely

Check our list of SSH commands for managing a Linux server How to Remotely Manage a Linux Server with SSH SSH is very functional, which is why it's a go-to for remote server management. Learn how to remotely manage a Linux server via SSH, from connection, to installing software, and file transfers. Read More for more.

Setup SSH and Make Linux More Powerful

With SSH, Linux becomes considerably more flexible and powerful. You can literally remotely access a computer using a smartphone thanks to SSH.

If SSH is set up correctly, with client and server-side software enabled and configured, remote command line access is possible. Need something more? Here’s how to remotely control a Linux desktop from Windows How to Remote Control Linux From Windows Need to remotely access your Linux desktop computer from Windows? Here's what you need to know about RDP, VNC, and SSH to Linux. Read More .

Related topics: Linux Tips, Remote Access, Remote Work, SSH, Terminal.

Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.

Whatsapp Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. rene vrancken
    May 24, 2020 at 1:48 pm

    can one connect windows 10 and linux ubuntu 20.04 on the same computer ? They cannot be both online.

  2. Azucar
    September 5, 2019 at 5:25 pm

    I use ssh for making updates on my programing files From another device 😄

  3. serJon
    June 27, 2019 at 2:03 pm

    Type with ifconfig -- should be ipconfig (P not F)

    • aloo
      October 25, 2019 at 1:52 am

      it is ifconfig not ipconfig

  4. anon
    May 16, 2018 at 2:57 am

    please do one on SSH keys. i just cannot understand how to put keys where and how!

  5. Jason Soto
    September 12, 2014 at 1:27 pm

    It is good to note that a basic configuration of SSH is not recommended when you are working on a production environment or critical systems. If this is a case is it good to take further steps to secure the connections, to mention a few, Use of SSH Keys, Different ports, Login protection, and others.

    • Tiffany
      September 13, 2014 at 1:52 pm

      I recommend configuring your key-pair require a passphrase to improve the security. Copy the public key to the server and add it to the authorized_keys files or a more advanced and flexible configuration uses ssh_config on the server or remote system.

  6. Zhong J
    September 11, 2014 at 4:17 am

    Are you guys planning to talk about SSH tunneling? Also, you can ssh into an lxc machine to setup an VPN (hypothetically).

  7. KT
    September 11, 2014 at 2:36 am

    I want to give that a try, but here's a question: I have pclinuxos mate on my pc, pclinuxos full monty on my wife's pc and zorin os 9 on my parts pc all wired to a cable modem. Will I run into compatibility issues with the different distros?

    • dragonmouth
      September 11, 2014 at 2:16 pm

      You shouldn't. After all, it will be the same version of SSH on all PCs. If SSH can handle connecting to different O/Ss, it should be able to handle connecting to different distributions of the same O/S.

  8. Steve
    September 10, 2014 at 6:43 pm

    Oh SSH. I absolutely love it and use it daily. Uses:

    *Tunneling - Set a dynamic port forward, (ssh -D 8888 server.com) and then in your browser config use a SOCKS5 proxy pointing to localhost:8888. All TCP traffic in the browser goes through the SSH host. TCP only, so DNS queries are not encrypted. Doing this, you can also get to your router's webpage doing this or any other web-servers this way. Also great for setting that show to record on your MythTV box from anywhere with internet! I've done this in the past week. If you have a rooted Android phone, you can do this via ProxyDroid too.
    *FTP / Accessing shared folders - Same vein, but you'd use locally forwarded ports instead of a dynamic one and point the client to localhost (ssh -L 8888:destination:22 user@go.between & ftp user@destination 8888 for example)
    *Update all of your computers from command line: "sudo apt-get update && sudo apt-get upgrade"
    *rsync backups / transfers: need to do incremental backups across the internet through a secure channel? Or even just incremental backups across your LAN. Or just transfers to locally attached drives. You already have everything you need! I normally use "rsync -Pa user@source user@destination" to preserve user and datestamp info, and show progress information.
    *Run a screen / byobu session on the SSH host and then running commands that will take a long time to do, an IRC client, etc. running inside the session. Easily detach and reattach later on and not setup everything all over again. During my college years, I could pop in and out of this screen session and chat on IRC with my friends among my classes throughout the day.
    *Running GUI-based programs through SSH via X forwarding; if your client is on linux, just use the -X option. It even works across multiple hops, assuming you use the -X option when connecting everywhere. Windows users have to download and install an X server (Xming is what I use) and tell their client to forward X sessions. Test out with running "xeyes" and run programs as if you were on the box right there. Even possible, though a bit of a pain, to do on an Android client.
    *Help out a techie friend - perform a reverse SSH connection. A bit hard to explain, so I'm just going to link: http://www.thegeekstuff.com/2013/11/reverse-ssh-tunnel/