Setting up your first Linux server can initially seem daunting, particularly for those new to server administration. However, the process is surprisingly straightforward, and with the correct guidance, you can have your Ubuntu server operational in a short amount of time.
This step-by-step guide will walk you through the entire setup, ensuring your server is not only functional but also secure and optimized for future use. Whether you aim to set up a web server, host applications, or simply explore Linux administration, this guide will provide a quick and confident start.
By the end of this tutorial, you will have a fully operational Ubuntu server, remotely accessible and customizable to meet your specific requirements.
Step 1: Choosing a Cloud Provider or Local Installation (5 Minutes)
Before you begin setting up your Ubuntu server, you need to decide on its location. You have two primary options: renting a cloud-based server (VPS) or installing Ubuntu Server on a physical machine. Your choice will depend on your intended use, budget, and level of technical expertise.
Option 1: Cloud Server (VPS) - Recommended for Beginners
For those without spare hardware or who prefer to avoid hardware configuration, a cloud-based Virtual Private Server (VPS) is the simplest route. Cloud providers offer pre-configured Ubuntu servers that can be deployed in minutes.
Popular beginner-friendly cloud providers include:
- DigitalOcean: Known for simplicity, affordability, and ease of use for beginners (
).https://www.digitalocean.com/ - Linode: Favored by developers, offering robust documentation and reliable performance (
).https://www.linode.com/ - Amazon Web Services (AWS): A more complex, yet powerful and highly scalable platform (
).https://aws.amazon.com/ - Google Cloud: Provides a free tier with limited resources, ideal for initial exploration (
).https://cloud.google.com/
Steps to Deploy an Ubuntu VPS:
- Sign up: Create an account with your chosen cloud provider.
- Create a server instance: Initiate a new server instance, often termed a "droplet" (DigitalOcean) or "instance" (AWS).
- Choose Ubuntu Version: Select Ubuntu 24.04 LTS, the latest Long-Term Support version, ensuring several years of security updates.
- Select a plan: Choose a plan that aligns with your needs. For experimentation, a small instance with 1 CPU and 1GB RAM is sufficient.
- Set up authentication: Opt for password or SSH key authentication. SSH keys are more secure and highly recommended.
- Launch and note IP: Launch the server and record the provided IP address, which is essential for connecting to your server.
Your cloud-based Ubuntu server is now set up and ready for access.
Option 2: Local Ubuntu Server Installation
If you have a spare computer or prefer to run Ubuntu on your hardware, you can manually install Ubuntu Server. This option is suitable for setting up a home lab, a private web server, or for in-depth Linux administration practice.
Requirements:
- A computer for Ubuntu Server installation.
- A USB flash drive (minimum 4GB).
- A separate computer to create a bootable USB drive.
Steps for Local Installation:
- Download Ubuntu Server ISO: Visit the
and download the latest Ubuntu Server 24.04 LTS ISO file.official Ubuntu website - Create a bootable USB drive:
-
Windows: Use Rufus (
)https://rufus.ie/en/ - Insert your USB drive.
- Open Rufus and select the downloaded ISO.
- Click 'Start' and wait for completion.
-
Linux/macOS: Use the
dd
command:Bashsudo dd if=ubuntu-24.04.1-live-server-amd64.iso of=/dev/sdX bs=4M status=progress
Replace
/dev/sdX
with your USB device path (uselsblk
to find this).
-
- Boot from USB: Insert the USB into your target machine, restart, and enter BIOS/UEFI settings (usually via F2, F12, DEL, or ESC during boot). Set the USB drive as the primary boot device and save changes.
- Ubuntu Server Installer: The installer will load automatically.
- Follow Installation Steps:
- Choose language and keyboard layout.
- Select 'Install Ubuntu Server'.
- Set up username and password.
- Choose disk partitioning (Guided – Use Entire Disk is simplest).
- Select 'Install OpenSSH Server' (recommended for remote access).
- Complete installation and reboot.
Once installed, log in with your created credentials.
Choosing the Right Option
Factor | Cloud Server (VPS) | Local Installation |
---|---|---|
Best for | Beginners, web hosting, remote Linux learning | Home labs, private servers, advanced users |
Setup Time | 5-10 minutes | 20-30 minutes |
Hardware | None required | Spare PC or server needed |
Access | Remote via SSH | Direct login or SSH (if configured) |
Cost | Monthly fee (from ~$5/month for basic VPS) | Free (excluding electricity and maintenance) |
Performance | Plan-dependent | Hardware-dependent |
For Linux novices or those seeking a straightforward setup, a cloud VPS is ideal. Conversely, if you have spare hardware and desire complete hardware control, local installation provides a valuable learning experience.
After setting up your Ubuntu server, the next step is to access and update it with the latest security patches.
sudo apt update && sudo apt upgrade -y
Step 2: Accessing Your Ubuntu Server (2 Minutes)
With your Ubuntu server running, you now need to access it. This is where you begin interacting with your server, installing software, and configuring it to your needs.
Accessing a Cloud Server (VPS)
Cloud providers like DigitalOcean, Linode, AWS, and Google Cloud will provide:
- A public IP address (e.g.,
192.168.1.100
). - A default username (typically
root
orubuntu
). - Password or SSH key for authentication.
Connecting via SSH:
-
Linux/macOS: Open your terminal and use the command:
Bashssh ubuntu@your-server-ip
Replace
your-server-ip
with your server's actual IP address. -
Windows: Use PuTTY (
):https://www.putty.org/ - Open PuTTY and enter your server's IP in 'Host Name (or IP address)'.
- Select 'SSH' as the connection type and click 'Open'.
- Enter your password when prompted (if using password authentication). For SSH keys, load your private key in PuTTYgen before connecting.
Successful login will display a welcome message with system details.
Accessing a Local Ubuntu Server
For local installations, power on the machine, wait for the login prompt, and enter the username and password created during setup. You will then access the Ubuntu command-line interface (CLI).
After logging in, update your server to ensure it has the latest security patches:
sudo apt update && sudo apt upgrade -y
Step 3: Creating a New User and Securing SSH Access (5 minutes)
By default, cloud providers often provide root user access. While root has full system control, it's risky for daily tasks. Accidental commands or security breaches can severely impact the system.
For enhanced security, create a new user with administrative rights and properly configure SSH access.
1. Create a New User
Add a new user for server tasks, replacing yourusername
with your desired username:
sudo adduser yourusername
Set a strong password when prompted and fill in optional fields or press Enter to skip.
2. Grant Administrative Privileges (sudo access)
Grant your new user administrative (sudo) privileges:
sudo usermod -aG sudo yourusername
Verify sudo access by switching to the new user and running:
su - yourusername
sudo whoami
If the output is root
, sudo access is correctly configured.
3. Set Up SSH Key Authentication
SSH keys are more secure than passwords. Generate an SSH key pair on your local computer:
ssh-keygen -t rsa -b 4096
Press Enter to save to the default location (~/.ssh/id_rsa
). Set a passphrase for added security (optional).
Copy SSH Key to Server:
-
Cloud Server (using
ssh-copy-id
):Bashssh-copy-id yourusername@your-server-ip
-
Manual Copy (if
ssh-copy-id
is unavailable):Bashssh root@your-server-ip sudo mkdir -p /home/yourusername/.ssh sudo chmod 700 /home/yourusername/.ssh echo "your-public-key" | sudo tee -a /home/yourusername/.ssh/authorized_keys > /dev/null sudo chmod 600 /home/yourusername/.ssh/authorized_keys sudo chown -R yourusername:yourusername /home/yourusername/.ssh
Replace
"your-public-key"
with the content of yourid_rsa.pub
file.
Test SSH key authentication by logging in with the new user:
ssh yourusername@your-server-ip
4. Disable Root Login and Password Authentication
Improve security by disabling root logins and password authentication in the SSH configuration:
sudo nano /etc/ssh/sshd_config
Modify these lines:
PermitRootLogin no
PasswordAuthentication no
Restart the SSH service:
sudo systemctl restart ssh
Test login via SSH with your new user. SSH access is now secured.
Step 4: Installing Essential Software (5 Minutes)
With your server secured, install essential software for efficient management and security.
Install Common Packages:
sudo apt install -y vim curl wget git htop unzip net-tools
vim
: Powerful text editor for configuration files.curl
&wget
: Command-line tools for downloading web files.git
: Version control for code repository management.htop
: Enhanced system resource monitoring tool.unzip
: For extracting.zip
files.net-tools
: Network utilities likeifconfig
.
Set Up UFW Firewall:
UFW (Uncomplicated Firewall) is essential for server security. Allow SSH traffic before enabling:
sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status
Configure Time and Synchronization:
Accurate server time is crucial. Ubuntu uses systemd-timesyncd
for automatic time synchronization.
timedatectl
timedatectl list-timezones
sudo timedatectl set-timezone Asia/Kolkata
timedatectl
Replace Asia/Kolkata
with your timezone.
Install Fail2Ban (Optional, Extra Security):
Fail2Ban protects against brute-force attacks:
sudo apt install -y fail2ban
sudo systemctl enable fail2ban
sudo systemctl start fail2ban
sudo systemctl status fail2ban
Enable Automatic Security Updates:
Enable automatic security updates:
sudo apt install -y unattended-upgrades
sudo dpkg-reconfigure --priority=low unattended-upgrades
cat /etc/apt/apt.conf.d/20auto-upgrades
Verify that APT::Periodic::Update-Package-Lists "1";
and APT::Periodic::Unattended-Upgrade "1";
are present.
Clean Up Unnecessary Files:
Remove temporary files and unused dependencies:
sudo apt autoremove -y
sudo apt autoclean
Step 5: Configuring a Web Server (Optional, 5–10 minutes)
For hosting websites or web applications, a web server is needed. Nginx and Apache are popular choices. This guide uses Nginx for its efficiency and beginner-friendliness.
Install Nginx on Ubuntu:
sudo apt update
sudo apt install -y nginx
nginx -v
Start and enable the Nginx service:
sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl status nginx
Allow HTTP (port 80) and HTTPS (port 443) traffic through UFW:
sudo ufw allow 'Nginx Full'
sudo ufw status
Test Nginx by opening a web browser and navigating to http://your-server-ip
. You should see the default Nginx welcome page.
Set Up a Basic Website (Optional):
Replace the default Nginx page with a custom website by editing /var/www/html/index.html
:
sudo nano /var/www/html/index.html
Replace the content with:
<!DOCTYPE html>
<html>
<head>
<title>Welcome to My Server</title>
<style>
body { text-align: center; font-family: Arial, sans-serif; margin-top: 50px; }
h1 { color: #4CAF50; }
</style>
</head>
<body>
<h1>Success! Your Nginx Web Server is Running.</h1>
<p>This is a test page hosted on Ubuntu.</p>
</body>
</html>
Refresh http://your-server-ip
in your browser to view your custom page.
Enable HTTPS with Let's Encrypt (Optional):
Enable HTTPS using a free SSL certificate from Let's Encrypt:
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx
You have now successfully installed and configured an Nginx web server on your Ubuntu server.
Conclusion
You have successfully set up your first Ubuntu server in under 30 minutes. This guide provides a foundation, and there is much more to explore, such as hosting websites, databases, and applications. As you gain experience, you will appreciate the power and versatility of Linux servers. Happy hosting!
0 comments:
Post a Comment