Welcome to the ultimate guide for setting up an Ubuntu Server! This step-by-step manual will help you install, configure, and secure your server, making sure it's ready for production or personal use. Whether you're a beginner or experienced, follow along to get your server up and running smoothly.
This guide will walk you through the following:
- Installing and configuring OpenSSH for remote access
- Setting a static IP address
- Installing essential software for server security and performance
- Setting up Samba to share the root directory
- Best practices for server management and regular maintenance
Let's get started!
Before starting, make sure the system is up to date.
sudo apt update && sudo apt upgrade -y
OpenSSH allows you to remotely access your server. To install it, run:
sudo apt install openssh-server -y
Once installed, check the status to ensure the service is running:
sudo systemctl status ssh
If not running, start and enable the service to launch on boot:
sudo systemctl start ssh
sudo systemctl enable ssh
To ensure your server always uses the same IP address, you’ll need to set a static IP.
-
Identify the Network Interface: Use the following command to list network interfaces:
ip a
Identify your main interface (e.g.,
eth0
orens160
). -
Modify the Netplan Configuration: Open the Netplan configuration file:
sudo nano /etc/netplan/00-installer-config.yaml
Update it with your network information:
network: version: 2 ethernets: <interface_name>: dhcp4: no addresses: - <your_static_ip>/24 gateway4: <your_gateway> nameservers: addresses: - <your_dns_server>
Replace
<interface_name>
,<your_static_ip>
,<your_gateway>
, and<your_dns_server>
with your specific values. -
Apply the Configuration:
sudo netplan apply
-
Test the Connection: Verify the server's connection by pinging an external address:
ping 8.8.8.8
You can now access your server from another machine using SSH:
ssh <your_username>@<your_server_ip>
Samba allows you to share files across different operating systems, such as Windows. To share the root directory with full access, follow these steps carefully:
Install Samba with the following command:
sudo apt install samba -y
Before making changes, it's a good idea to backup the default Samba configuration file:
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
Open the Samba configuration file to set up sharing of the root directory:
sudo nano /etc/samba/smb.conf
Add the following at the end of the file:
[Root]
path = /
available = yes
valid users = <your_username>
read only = no
browsable = yes
public = yes
writable = yes
force user = root
Make sure to replace <your_username>
with the username you want to grant access to.
You need to set a Samba password for your user:
sudo smbpasswd -a <your_username>
To apply the changes, restart the Samba service:
sudo systemctl restart smbd
From a Windows machine, access the server's shared directory by typing the server's IP in File Explorer:
\<your_server_ip>
Log in with the username and password you created for Samba.
Below are some useful software tools for managing and optimizing your server.
Fail2Ban monitors logs and bans IPs that show malicious signs, such as repeated failed login attempts.
sudo apt install fail2ban -y
You can adjust its settings in /etc/fail2ban/jail.conf
to suit your security needs.
UFW is an easy-to-use firewall tool to manage access to your server.
sudo apt install ufw -y
sudo ufw allow OpenSSH
sudo ufw enable
Docker allows you to run applications in isolated containers, which is great for deploying and testing software environments.
sudo apt install docker.io -y
sudo systemctl start docker
sudo systemctl enable docker
htop is an interactive system monitor that provides a detailed view of system processes and resource usage.
sudo apt install htop -y
The net-tools
package includes networking utilities like ifconfig
, useful for debugging network issues.
sudo apt install net-tools -y
You can install either Apache or Nginx, depending on your preference.
-
Apache:
sudo apt install apache2 -y
-
Nginx:
sudo apt install nginx -y
Install a database server based on your application needs.
-
MySQL:
sudo apt install mysql-server -y
-
PostgreSQL:
sudo apt install postgresql postgresql-contrib -y
certbot allows you to easily manage SSL certificates from Let’s Encrypt.
For Nginx:
sudo apt install certbot python3-certbot-nginx -y
For Apache:
sudo apt install certbot python3-certbot-apache -y
Keep track of server logs using journalctl
:
sudo journalctl -xe
To keep your server secure and up to date, periodically run:
sudo apt update && sudo apt upgrade -y
You can also enable automatic security updates:
sudo apt install unattended-upgrades -y
Edit the config file:
sudo dpkg-reconfigure --priority=low unattended-upgrades
To keep your server running smoothly, follow these best practices:
- Regular Backups: Always perform regular backups of critical data using tools like
rsync
or backup services. - Security Hardening: Use tools like Fail2Ban, and consider setting up SSH keys for more secure authentication.
- Monitor Performance: Utilize
htop
or other monitoring tools to ensure your server is performing well under load. - Use Docker for Deployment: Docker containers can isolate applications, making deployments cleaner and easier to manage.
- Test on a Local Server First: If possible, deploy new services and applications on a test server before moving to production.
Your Ubuntu Server is now set up with OpenSSH for remote access, a static IP address for consistent networking, Samba for file sharing, and several recommended tools for improving security, performance, and management. Follow the best practices to maintain your server’s health and security over time. Keep your system updated, monitor performance, and secure access to prevent unauthorized activities.
With this setup, you're ready to run a stable and secure server environment. Enjoy your newly configured Ubuntu Server!