How to Configure SSH on Ubuntu Server: A Complete Step-by-Step Guide
Secure Shell (SSH) is one of the most important tools for managing an Ubuntu Server. It allows you to connect to a remote machine, execute commands, transfer files, and administer your server without needing physical access to it.
Whether you are setting up a home server, managing a cloud VPS, or deploying a website, configuring SSH correctly makes remote administration easier and more secure.
In this guide, you will learn how to install the SSH server on Ubuntu, configure its settings, authenticate using SSH keys, enable firewall access, and troubleshoot common connection problems.
What Is SSH in Ubuntu?
SSH stands for Secure Shell. It is a network protocol that creates an encrypted connection between a client computer and a remote server.
Unlike older remote-access tools that transmit information without adequate protection, SSH encrypts communication between the two systems. This helps protect login credentials, commands, and transmitted data from interception.
SSH typically uses TCP port 22 by default, although administrators can configure it to listen on another port.
With SSH, you can:
- Manage Ubuntu servers remotely through a terminal.
- Transfer files securely between computers.
- Run administrative commands without being physically present.
- Authenticate using passwords or cryptographic keys.
- Create secure tunnels for forwarding network traffic.
Step 1: Update Your Ubuntu Server
Before installing or configuring SSH, update your server's package information and install available upgrades.
Open a terminal or access your server through your hosting provider's console, then run:
sudo apt update
sudo apt upgrade
The first command refreshes the package index, while the second installs available package upgrades.
Keeping Ubuntu updated helps ensure that your system receives security fixes and bug corrections.
Step 2: Install the OpenSSH Server
Ubuntu uses OpenSSH to provide SSH connectivity. The server component accepts incoming connections, while the client component lets you connect to other machines.
To install the SSH server, execute:
sudo apt install openssh-server
If the package is already installed, APT will report that it is up to date or already installed.
Next, check whether the SSH service is running:
sudo systemctl status ssh
Look for a status indicating that the service is active and running.
If SSH is installed but not running, start it with:
sudo systemctl start ssh
To make SSH start automatically whenever the server boots, run:
sudo systemctl enable ssh
You can also enable and start the service in one command:
sudo systemctl enable --now ssh
Step 3: Find Your Ubuntu Server's IP Address
To connect remotely, you need the IP address of your Ubuntu Server.
Run:
hostname -I
This command displays the IP addresses assigned to the server.
For more detailed network information, use:
ip addr
Suppose your server's reachable IP address is 192.168.1.100. From another computer on the same network, you can connect with:
ssh username@192.168.1.100
Replace username with your actual Ubuntu account name and replace the example IP address with your server's address.
For a server hosted on the internet, use the public IP address or hostname supplied by your hosting provider. Make sure your network and hosting firewall permit SSH connections.
Step 4: Configure the SSH Server
OpenSSH stores its main server configuration in this file:
/etc/ssh/sshd_config
Before changing anything, create a backup:
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup
Open the configuration file with Nano:
sudo nano /etc/ssh/sshd_config
You can adjust several settings to control how users connect to your server.
Change the SSH port
The default SSH port is 22. You can configure a different port, such as 2222, by adding or editing this line:
Port 2222
Changing the port may reduce automated login attempts that target the default port, but it is
Comments
Post a Comment