Server management remains a necessary and occasionally cumbersome task. It’s especially difficult with remote servers or headless servers. Thankfully, there’s Secure Shell (SSH). Secure Shell is a network protocol that allows for network services to run over an unsecured network.
So here are some easy tips for remotely manage a Linux server via SSH, from connection to installing software and file transfers.
Preparing Your Server to Accept SSH
Before you begin managing your Linux server via SSH, you’ll have to prepare your server to allow SSH connections. I have a headless dedicated Plex media server. Lacking a monitor and peripherals, I use SSH to manage my server. When installing or updating software and transferring files, I simply SSH into my server. My exact set up is a ThinkServer TS140 running Ubuntu 16.04 LTS. Depending on your hardware and Linux distribution, prepping for SSH may vary slightly.
To prep your Linux server to accept incoming connections, you’ll need to install a remote login tool for the SSH protocol. One of the most common is OpenSSH. On Debian-based distributions, OpenSSH is available via the main repositories. Open a new terminal (Ctrl + Alt + T) and enter the following command:
sudo apt-get update
This performs an update and ensures you’ve got the latest repositories. Before proceeding to install OpenSSH, also check for any upgrades. In a terminal, run:
sudo apt-get upgrade
Once you’ve updated and upgraded, open a new command line and enter:
sudo apt-get install openssh-server
Configuring Your Server SSH Settings
After Open SSH has been installed server side, you can edit basic configuration info. Pull up a fresh terminal and enter the following string to open the SSH config file:
sudo nano /etc/ssh/sshd_config
Here you can specify various settings. By default your SSH server will operate on port 22. So, for instance, you can manually change the port from 22 to a port of your choosing. Additionally, you may increase security by entering a maximum login number. Under Port, find the line MaxAuthTries. You can input any number here. So to make a maximum login attempt count of four, enter:
After installing OpenSSH, the SSH server should be running. But to check, simply open a terminal and run:
sudo service ssh status
This should return a message that SSH is enabled. To start SSH, open a command line and enter:
sudo service ssh start
And to stop SSH from running, run:
sudo service ssh stop
Remotely Accessing a Linux Server via SSH
Now that SSH is installed and running, you can connect remotely. If you’re logging into a Linux server remotely, you’ll need the IP address of the server. This should be 192.168.0.x. Armed with the Linux server IP address, you’ll also need a means of logging in via SSH from a different machine. There are several methods for logging in remotely with SSH.
Using SSH on Unix-Based Operating Systems
If you’re using a Unix-based system like Linux, macOS, or FreeBSD, SSH is available in the command line. In a terminal, run:
ssh [remote host]
…where [remote host] is the IP address you’re accessing. If your username differs on the remote system, you can specify the exact username by entering:
ssh [remote username]@[remote host]
After entering this, you’ll be asked if you want to continue connecting. Then you’ll be prompted to enter your username and then asked for your password.
Alternately, if you’d like to skip the command line altogether, you can log into your Linux server via the network. On a Linux machine, navigate to Connect to Server and enter your ssh://[IP address]. You’ll be asked to provide your username and password.
The main advantage of this method is that you’ll have complete graphical folder navigation. This is called SSH File Transfer Protocol, or SFTP. This makes file transfers much easier. Since my Linux server is a dedicated Plex server, unless I’m performing updates, I usually use SFTP.
SSH With PuTTY
If you’re using a PC or Mac, you’ll need an SSH client. PuTTY is probably the most well-known SSH client. Install PuTTY on your PC, macOS, or Linux machine. With PuTTY open, look under Session and in the box labeled Host Name, enter your IP address. Make sure to specify the correct port. If using the default, leave this as 22.
Now you should see a terminal with a login prompt. Enter your Linux server username here.
Once you’ve entered your username, you’ll be prompted for a password if you’ve got your Linux server password-protected. Enter that and you should see a welcome message with information about your system and a command line like you’d see on your Linux server.
Alternate SSH Clients
Although PuTTY remains the most popular SSH client, there are loads of alternatives. My top pick is Bitvise (Windows only). The reason? It includes not only the command line interface for remotely managing a Linux server via SSH, but SFTP capabilities. Thus, it’s perfect for both file transfers and general management. When I need to simply update or perform a reboot, I use Bitvise SSH Client for command line access. But for file transfers, I use the graphical interface.
Like with PuTTY or starting SSH via the command line on Linux, you’ll need to enter your IP address, username, and password.
You’ll recieve a prompt asking if you’d like to accept the session. You can accept for just that session or save for future use. After that, you’ll be asked to input the password of your Linux server that you’re remotely managing.
Plug that in and Bitvise will open both a command line and graphical SSH window.
The SFTP window makes managing file transfers really simple, plus there’s the traditional SSH command line for lots of functionality.