Horje
Remote Server Management from the Ubuntu Terminal

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.

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

STEP 3: Performing Backups with rsync

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.

Tools for Enhanced Remote Management

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.

STEP 3: Utilizing Monitoring Tools like Nagios and Zabbix

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.

Remote-Server-Management-from-the-Ubuntu-Terminal

Remote Server Management from the Ubuntu Terminal – FAQ’s

Recommended security measures for handling remote servers through SSH involve utilizing SSH keys rather than passwords, configuring firewalls with ` ufw ` to permit only essential traffic, implementing ` fail2ban ` to block brute force attempts, consistently updating applications to fix security flaws, and establishing two-factor authentication (2FA) for enhanced protection.

What are the fundamental steps to configure SSH for managing remote servers on Ubuntu?

To configure SSH for managing remote servers on Ubuntu, first, install the SSH server with ` sudo apt install openssh-server`, then activate and initiate the SSH service with ` sudo systemctl enable ssh ` and ` sudo systemctl start ssh`, generate SSH keys with ` ssh-keygen -t rsa -b 4096`, and lastly, transfer your public key to the remote server using ` ssh-copy-id username@remote_host`.

How can I establish a connection to a remote server via SSH from an Ubuntu terminal?

To establish a connection to a remote server via SSH from an Ubuntu terminal, open the terminal and input ` ssh username@remote_host ` , substituting `username` for your remote server’s username and ` remote_host ` for the server’s IP address or hostname.




Reffered: https://www.geeksforgeeks.org


TechTips

Related
How to Make UPI Payment Without Internet? How to Make UPI Payment Without Internet?
How to Enable Gmail Dark Mode? How to Enable Gmail Dark Mode?
How to Verify Checksum of a File in Windows? How to Verify Checksum of a File in Windows?
How to Find All Failed SSH Login Attempts in Linux System? How to Find All Failed SSH Login Attempts in Linux System?
How to Install lxml on Ubuntu? How to Install lxml on Ubuntu?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
26