![]() |
VOOZH | about |
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.
Table of Content
To start managing a remote server, A user needs SSH installed in their OS or Ubuntu System. Then run the following commands:
sudo apt updatesudo apt install openssh-serverAfter installation, Make sure the SSH server is running perfectly:
sudo systemctl enable sshsudo systemctl start sshSSH keys enhance security. Generating a key pair using:
ssh-keygen -t rsa -b 4096 -C "abc@example.com"For Connecting, Use:
ssh username@remote_hostRun the commands on the remote server directly:
ssh username@remote_host 'command_to_run'Securely copy files between your local machine and the remote server:
scp localfile username@remote_host: /path/to/remote/directoryFor more interactive file transfer sessions, use SFTP:
sftp username@remote_hostNow, securely access services on your remote server by creating tunnels:
ssh -L local_port:remote_host:remote_port username@remote_hostSimplify connections using an SSH config file (~/.ssh/config):
Host server1
HostName remote_host1
User username
IdentityFile ~/.ssh/id_rsa
Load the keys into the SSH agent for easier access:
ssh-add ~/.ssh/id_rsaSpeed up multiple SSH connections by configuring multiplexing:
Host *
ControlMaster auto
ControlPath ~/.ssh/sockets/%r@%h-%p
ControlPersist 600
Install htop for a real-time view of system performance:
sudo apt install htophtop
Check active connections and listening ports:
netstat -tulnSTEP 3: Checking Disk Usage with df and du
Monitor disk space usage:
df -hdu -sh /path/to/directorySTEP 4: Monitoring Logs with tail and grep
Track log files for issues:
tail -f /var/log/sysloggrep "error" /var/log/syslogControl services using systemctl:
sudo systemctl start service_namesudo systemctl stop service_nameSTEP 2: Checking Service Status
Now, check the status of a service:
sudo systemctl status service_nameEnable or disable services at startup:
sudo systemctl enable service_namesudo systemctl disable service_nameKeep your server updated:
sudo apt updatesudo apt upgradeAutomate tasks using cronjobs:
crontab -eBackup data efficiently:
rsync -avz /source/directory /destination/directoryUse `
fdisk`and `lsblk`to manage disks and partitions.
STEP 1: Configuring Firewalls with ufw
Set up a firewall for added security:
sudo ufw allow sshsudo ufw enableInstall and configure Fail2Ban:
sudo apt install fail2banEnsure all software is up-to-date to prevent vulnerabilities:
sudo apt updatesudo apt upgradeAdding an extra protection of security with 2FA for user's benefits.
Keeping sessions alive even after disconnecting:
tmux
screen
Automate server management tasks with Ansible.
Set up comprehensive monitoring for your servers.
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.