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.
SSH boasts a ton of functionality. There’s a reason 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.
What Is SSH?
SSH stands for Secure Shell. It’s a cryptographic network protocol. Using SSH, you can gain terminal access and perform various command line functions. There are also means of managing a Linux server with graphical access. This is really useful for file transfers, particularly when you don’t want to or can’t remember an exact file path.
When using SSH to manage a remote Linux server, you’ll need a few items. First, you’ll need to prepare your server to accept SSH connections. On the devices you’ll be connecting from, you’ll require some sort of SSH software. To log into a server with SSH, you’ll need to know the IP address of the server. However, logging in via SSH with an IP address only works if you’re on the same local network as the server. If you’re outside your network, you can set up a port forward to access a server with SSH from anywhere. You can learn more about SSH in this beginners guide to setting up SSH on Linux.
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.
How You Can Manage a Remote Linux Server With SSH
Okay, great! SSH is configured both on the server and the device you’ll use to manage your server. So, what can you actually do? Anything that’s possible with the Linux command line. Some common tasks you may preform are software installs, updates, reboots, copy files, and even run GUI applications. For example, you can copy files with the following commands:
scp [remote host]:[local file] [destination directory]
scp [local file] [remote host]:[destination directory]
Installing software merely means plugging in the proper command. When I installed Plex on my headless TS140 via SSH for example, I merely entered:
sudo apt-get install plexmedia server -y
Similarly, to say create a WordPress server, you would just follow the install details but via a SSH command line.
What you do likely depends on the server and what it’s used for. As I run a headless dedicated Plex server, most of what I use SSH and SFTP for is file transfers with occasional software updates. I’ve also used SSH to access log files and run benchmarks to test CPU performance. If you’re running a web server, you may wish to backup your website using the SSH command line. Check out this quick primer to the Linux command line, as well as these three sites to help you evolve into a Linux command line master.
SSH: Finding the Remote
If you’re running a Linux server, SSH is a superb means of managing it remotely. You retain full command line control, and can even run GUI apps and perform file transfers. There are near limitless possibilities to what you can accomplish when managing a remote Linux server via SSH. You can set up a file server, media server, Linux game server, and more. You can even manage a headless Raspberry Pi server using SSH. What’s more, many SSH client programs are cross-platform.
How are you using SSH and what sort of server are you managing?
Explore more about: Linux.