Remote Server Management from the Ubuntu Terminal
Last Updated :
13 May, 2025
Controlling servers from a distance is an extremely important job for system admins, users, and programmers. It guarantees that the servers are operating correctly, and safely, and are current with the newest software updates. A highly effective tool for handling remote servers is the Ubuntu terminal. This guide will take you through the process of setting up, overseeing, and keeping remote servers in good shape, offering you key commands and top tips.
Syntax for Setting-Up SSH (Secure Shell)
STEP 1: Installing SSH on Ubuntu
To start managing a remote server, A user needs SSH installed in their OS or Ubuntu System. Then run the following commands:
sudo apt update
sudo apt install openssh-server
STEP 2: Configuring SSH Server
After installation, Make sure the SSH server is running perfectly:
sudo systemctl enable ssh
sudo systemctl start ssh
STEP 3: Generating SSH Keys
SSH keys enhance security. Generating a key pair using:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
Basic SSH Commands to Connect Remote Server
STEP 1: Connecting to a Remote Server
For Connecting, Use:
ssh username@remote_host
STEP 2: Executing Commands Remotely
Run the commands on the remote server directly:
ssh username@remote_host 'command_to_run'
STEP 3: Transferring Files with SCP
Securely copy files between your local machine and the remote server:
scp localfile username@remote_host: /path/to/remote/directory
STEP 4: Using SFTP for File Management
For more interactive file transfer sessions, use SFTP:
sftp username@remote_host
Advanced SSH Techniques
STEP 1: SSH Tunneling and Port Forwarding
Now, securely access services on your remote server by creating tunnels:
ssh -L local_port:remote_host:remote_port username@remote_host
STEP 2: Managing Multiple Servers with SSH Config File
Simplify connections using an SSH config file (~/.ssh/config
):
Host server1
HostName remote_host1
User username
IdentityFile ~/.ssh/id_rsa
STEP 3: Using SSH Agent for Key Management
Load the keys into the SSH agent for easier access:
ssh-add ~/.ssh/id_rsa
STEP 4: Setting Up SSH Multiplexing
Speed up multiple SSH connections by configuring multiplexing:
Host *
ControlMaster auto
ControlPath ~/.ssh/sockets/%r@%h-%p
ControlPersist 600
Monitoring Remote Servers
STEP 1: Installing and Using htop for Resource Monitoring
Install htop for a real-time view of system performance:
sudo apt install htop
htop
STEP 2: Using netstat for Network Monitoring
Check active connections and listening ports:
netstat -tuln
STEP 3: Checking Disk Usage with df and du
Monitor disk space usage:
df -h
du -sh /path/to/directory
STEP 4: Monitoring Logs with tail and grep
Track log files for issues:
tail -f /var/log/syslog
grep "error" /var/log/syslog
Managing Services on Remote Servers
STEP 1: Starting and Stopping Services
Control services using systemctl:
sudo systemctl start service_name
sudo systemctl stop service_name
STEP 2: Checking Service Status
Now, check the status of a service:
sudo systemctl status service_name
STEP 3: Managing Services with systemctl
Enable or disable services at startup:
sudo systemctl enable service_name
sudo systemctl disable service_name
Remote Server Maintenance
STEP 1: Updating and Upgrading Packages
Keep your server updated:
sudo apt update
sudo apt upgrade
STEP 2: Scheduling Tasks with cron
Automate tasks using cron jobs:
crontab -e
Backup data efficiently:
rsync -avz /source/directory /destination/directory
STEP 4: Disk Management and Partitioning
Use ` fdisk
`and ` lsblk
`to manage disks and partitions.
Security Best Practices
STEP 1: Configuring Firewalls with ufw
Set up a firewall for added security:
sudo ufw allow ssh
sudo ufw enable
STEP 2: Using Fail2Ban to Prevent Brute Force Attacks
Install and configure Fail2Ban:
sudo apt install fail2ban
STEP 3: Regularly Updating Software for Security Patches
Ensure all software is up-to-date to prevent vulnerabilities:
sudo apt update
sudo apt upgrade
STEP 4: Setting Up Two-Factor Authentication (2FA)
Adding an extra protection of security with 2FA for user's benefits.
STEP 1: Using tmux and screen for Persistent Sessions
Keeping sessions alive even after disconnecting:
tmux
screen
STEP 2: Installing and Configuring Ansible for Automation
Automate server management tasks with Ansible.
Set up comprehensive monitoring for your servers.
Conclusion
Controlling servers located far away through the Ubuntu command line is a strong and effective method for keeping your systems up and running. By becoming skilled in SSH, using monitoring software, managing services, and following top security practices, you can make sure your servers operate without problems and are safe. Consistent upkeep and oversight are crucial for avoiding problems and keeping your systems performing at their best.
Similar Reads
What is System Management Server (SMS) - Complete Overview System Management Server (SMS), now known as Microsoft Endpoint Configuration Manager (MECM), is an enterprise-level management solution from Microsoft that is used to manage and maintain computers and devices within a corporate environment. It allows IT administrators to efficiently monitor, update
11 min read
How to Browse From the Linux Terminal Using W3M? W3M is an open-source text-based terminal web browser for Linux used to browse through the terminal. It is simple to use and do not require any additional interacting interface application though it interacts through the terminal. It renders the web pages in a form as their original layout. How to I
1 min read
How to Browse From the Linux Terminal Using W3M? W3M is an open-source text-based terminal web browser for Linux used to browse through the terminal. It is simple to use and do not require any additional interacting interface application though it interacts through the terminal. It renders the web pages in a form as their original layout. How to I
1 min read
How to use SSH to connect to a remote server in Linux | ssh Command Secure Shell, commonly known as SSH, is like a super-secure way to talk to faraway computers, called servers. It's like a secret tunnel on the internet that keeps your conversations safe and private. Imagine you're sending a letter, and instead of sending it openly, you put it in a magic envelope th
8 min read
How to use SSH to connect to a remote server in Linux | ssh Command Secure Shell, commonly known as SSH, is like a super-secure way to talk to faraway computers, called servers. It's like a secret tunnel on the internet that keeps your conversations safe and private. Imagine you're sending a letter, and instead of sending it openly, you put it in a magic envelope th
8 min read
How to Set Up Remote Desktop Access From Windows to Ubuntu? systemRemote Desktop from Windows helps to access a different operating system in Windows itself. Windows & Ubuntu operating systems can be used simultaneously with the help of Remote Desktop Access. Remote Desktop Access on Ubuntu from the Windows process will be discussed in this article by fo
5 min read