Hosting + Ai Website Builder + Free Domain (3 Month Free Credit)
Shop Today

Ultimate Guide to Use SSH on Linux Servers Safely

Use SSH on a Linux server to securely connect and manage your remote systems over the network. SSH, or Secure Shell, is a cryptographic protocol that provides a safe channel to log into another computer, execute commands, transfer files, and perform administrative tasks securely.

OpenSSH on a Linux

This guide will show you how to use SSH on a Linux server, including installation, connection methods, basic security practices, and management tips.

Prerequisites

  • A Linux server running Ubuntu, Debian, CentOS, Red Hat, or similar
  • Root or sudo privileges to install and configure the SSH server
  • Network connectivity to the remote Linux server
  • An SSH client installed on your local machine (usually preinstalled on Linux/macOS; available as OpenSSH on Windows)

Steps to Use SSH on the Linux Server

Using SSH (Secure Shell) on a Linux server allows secure, encrypted remote access and command execution across networked systems. SSH is essential for system administrators, developers, and anyone managing Linux environments remotely. It enables you to log in to servers, transfer files securely, and automate administrative tasks — all while maintaining a high level of security. With SSH, you can manage multiple systems without exposing sensitive credentials or data over the network.

Step 1: Install OpenSSH Server on Linux

Some Linux distributions come with SSH pre-installed; if not, you can install the OpenSSH server using your package manager.

  • Ubuntu/Debian:
sudo apt update sudo apt install openssh-server
  • CentOS/Red Hat/Fedora:
sudo yum update sudo yum install openssh-server

This installs the SSH server daemon (sshd) that listens on the default port 22 to accept SSH connections.

Step 2: Start and Enable the SSH Service

Start the SSH server to accept connections and enable it to run on boot.

  • Start the SSH service:
sudo systemctl start sshd
  • Enable SSH service on boot:
sudo systemctl enable sshd
  • Check service status:
sudo systemctl status sshd

If sshd is active and running; your server is ready to accept SSH connections.

Step 3: Connect to Your Linux Server Using SSH

From a client machine, use the SSH command to connect:

ssh username@server_ip_or_hostname

Replace username with the remote server user account and server_ip_or_hostname with the server’s IP address or domain name. On first connection, verify and accept the host fingerprint.

You will be prompted for the user’s password (unless using SSH keys) and then gain shell access to the remote Linux server.

Step 4: Secure Your SSH Server

To increase security while you use SSH on a Linux server:

  • Edit the configuration file:
sudo nano /etc/ssh/sshd_config

Important settings to consider:

  • Disable root login via SSH:
PermitRootLogin no
  • Enable only SSH protocol version 2: (default in modern setups)
Protocol 2
  • Change default SSH port: Change Port 22 to another number to reduce automated attacks.
  • Disable password authentication (optional after setting up keys):
PasswordAuthentication no

After changes, restart the SSH service:

sudo systemctl restart sshd

SSH keys provide a more secure and convenient way to authenticate.

  • Generate a key pair on the client machine:
ssh-keygen
  • Copy the public key to the server:
ssh-copy-id username@server_ip_or_hostname

Now you can log in without a password prompt, provided the private key is available on your client.

Step 6: Basic SSH Commands and Tips

  • Disconnect from SSH session:
exit
  • Run a remote command without an interactive shell:
ssh username@server_ip_or_hostname 'command_to_run'
  • Copy files between local and remote:
scp localfile username@server_ip:/remote/directory/

Or download from remote:

scp username@server_ip:/remote/file localdir/
  • Check current SSH connections on the server:
sudo netstat -tnpa | grep ssh

Conclusion

To use SSH on a Linux server means securely connecting to your remote Linux system to manage, configure, and transfer files efficiently. Installing and running the OpenSSH server enables encrypted communication over unsecured networks. Adopting SSH key-based authentication and adjusting default settings enhances security significantly.

Mastering SSH gives you powerful control over your Linux servers from anywhere, laying the foundation for effective remote administration and development. For more, visit the OpenSSH Official documentation.

Himanshu Joshi

Leave a Comment

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

Scroll to Top