Initial Linux Server Setup
Initial Linux Server Setup
Following instructions have used placeholders shown below. Replace these placeholders with appropriate values before executing the instructions.
<yourdomain.com><user_name><your_email_id>
a. Create a non-root user
ssh root@<yourdomain.com>
adduser <user_name>
usermod -aG sudo <user_name>
exit
b. Set up passwordless SSH access (from your local machine)
# On your local machine
cd ~/.ssh
ssh-keygen # skip if a key already exists
scp id_rsa.pub <your_email_id>:~/.ssh/authorized_keys
Log in as the new user for all remaining steps:
ssh <user_name>@<yourdomain.com>
c. Update the system
sudo apt update && sudo apt upgrade -y
d. Create swap space
Recommended for small servers with 4GB of RAM or less. First, check if swap is already configured by running free -h. The command below creates a 1GB swap file. However, it is generally recommended to match your swap size to your total RAM.
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
# Make permanent
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab