Introduction
Due to recent hardware failures, I decided to perform a fresh installation of a Linux-based server, leveraging the opportunity to optimize its configuration.
Deploying a Linux server unlocks a wide range of functionalities, including:
- DNS server: Used for blocking ads and related applications.
- Remote development: Allows continuous development on trusted computers.
- Web server: Set up websites using Nginx or Apache, along with database services.
- Proxy server: For bypassing restrictions or NAT traversal.
- Simple file server: Not recommended as a standard NAS, as data maintenance costs are high. It’s better to use a ready-made NAS solution.
- Local AI Model Deployment: AI models like DeepSeek R1 14B can be deployed on servers or low-power devices such as Raspberry Pi, for tasks involving inference or language processing. This is suitable for development, testing, and automation applications, especially in environments with limited resources where basic NLP tasks are performed.
Performance requirements for the server should be determined based on individual needs. For example, setting up a web server requires considering security measures such as firewalls; whereas running AI models necessitates evaluating external graphics cards, RAM, and CPU performance to ensure smooth operation.
Host Selection
Before installing a Linux server, the first step is to choose the appropriate execution environment. The common options for hosting environments include:
- Physical Host (Local Server): Install Linux directly on hardware such as mini PCs, including
Intel NUC
andRaspberry Pi
, among other common options. - Virtualized Host: Use technologies like WSL and Docker to deploy and manage Linux environments within an existing system, enabling lightweight virtualization.
- Cloud Hosting:
- Shared Hosting: Multiple users share server resources, but their environments remain relatively independent. It is commonly used for small websites and blogs. Suitable for beginners as system management is not required.
- Virtual Private Server (VPS): A physical server is divided into multiple independent virtual servers, each with its own operating system and administrative privileges. It offers full control, making it suitable for developers who need a customized environment.
- Bare Metal Server: Provides an entire physical server without a virtualization layer, meaning all hardware resources are fully dedicated to a single tenant. Ideal for high-performance applications and enterprise deployments.
My Hosting Choice
I assemble my own hardware, including the case, motherboard, CPU, RAM, SSD, and power supply. The primary use cases include:
- Remote access and management
- Web scraping and data processing
- Hosting web servers and deploying applications
If the goal is to set up an ad-blocking server (e.g., AdGuard Home) or manage smart home devices with Home Assistant, I recommend using a Raspberry Pi. Its ARM architecture provides lower power consumption and cost advantages.
If a dedicated physical server is not an option, a VPS offers a flexible alternative. However, compared to bare-metal deployments, VPS instances often come with hardware resource constraints and potential data security concerns.
Popular Third-Party VPS Providers
- Amazon Web Services (AWS)
- Google Cloud Platform (GCP)
- Microsoft Azure
- DigitalOcean
- Vultr
- Linode
These services charge based on usage or a monthly subscription. The estimated cost for lightweight instances is $0.093–$0.15 per hour or $10–$30 per month.
Choosing a Linux Distribution
Since my primary use case involves hosting services, web development, and infrastructure setup, I chose to install Ubuntu Server 24.04. However, some SDKs require Ubuntu 18.04 as the development environment. When selecting a distribution, it’s essential to base your decision on your specific development needs and environment.
Here’s a comparison of different Linux distributions, their ideal user groups, and key features:
Distribution | Ideal Users | Key Features |
---|---|---|
Ubuntu | General users, developers, beginners | The most popular Linux distribution, widely supported. LTS versions are stable, while short-term releases feature newer updates. |
Linux Mint | Windows switchers | User-friendly, stable, ideal for daily use, and offers multiple desktop environments. |
MX Linux | Lightweight users | Suitable for older computers, includes built-in system management tools, stable and easy to use. |
Debian | Servers, developers | Highly stable with long-term support, but software versions may be outdated. |
Pop!_OS | Productivity, STEM students | Offers automatic window tiling, suitable for scientific computing and development, with built-in privacy features. |
Fedora | Developers who want the latest tech | Rapid adoption of new technologies, strong official support, great for development but less suited for long-term stability. |
openSUSE | Enterprise, server users | Available in stable (Leap) and rolling release (Tumbleweed) versions, suitable for enterprise and professional users. |
EndeavourOS | Users wanting to learn Arch | Provides a simplified Arch installation while maintaining a native Arch experience with rolling updates. |
Manjaro | Arch beginners | Includes built-in driver management, a more stable Arch-based variant, and is desktop-friendly. |
The main reason for using Ubuntu is its friendliness to beginners, avoiding many difficulties encountered by professionals. Additionally, most tasks can be developed normally on any distribution. Therefore, when choosing a distribution, you don’t need to be overly concerned, just choose the one you like.
As of June 2024, if you want to develop the NVIDIA Optimized Deep Learning Framework, the official support is only for Ubuntu 22.04, so be sure to check if the framework you want to develop supports your expected Linux distribution.
Disk Partitioning During Ubuntu Server 24.04 Installation
During the installation of Ubuntu Server 24.04, the interface mainly relies on keyboard interaction, making the operation relatively simple.
The installation process involves disk partitioning, which can be referenced from Ubuntu Disk Space Recommendations and Strategies.
Partition | Size | My Partition |
---|---|---|
/ | At least 15 GB | 30 GB (ext4) |
/boot | 250 MB ~ 1 GB | 500 MB (ext4) |
/var | 2 GB | 2 GB (ext4) |
swap | Size of RAM | 8 GB (ext4) |
/home | Remaining space | 151.34 GB (ext4) |
The
/
partition serves as the root directory of the system, with an official recommendation of at least 15 GB. Over time, log files, temporary caches, and installed packages may accumulate, potentially leading to system performance degradation or operational failures. To prevent such situations, I used twice the size to reduce errors. It is still recommended to regularly clean up the root partition files or adjust the root partition size when space is insufficient./boot for most UEFI systems is 500 MB ~ 1 GB.
For general desktop systems, allocating 1-2 GB for /var is sufficient. For server systems, especially those generating a lot of system logs (such as web servers), it is recommended to allocate 5 GB or more to the /var partition to prevent log files from filling up the root directory. When using Docker, it is recommended to allocate at least 20 to 50 GB of disk space for /var. If the initial space planning is too small, you can modify /etc/docker/daemon.json to change the default path /var/lib/docker/ to another directory or use symbolic links to solve the problem.
Swap should be configured to 1.5 ~ 2 times the system RAM, for example, if you have 4 GB of RAM, set SWAP to 6 GB. If you have more than 8 GB of RAM, 1x SWAP is sufficient.
Leave the remaining space for /home, or plan other partitions as needed.
After verifying that all partition settings are correct, you can proceed with the official installation of the system. Once the installation is complete and the system is restarted, it will successfully boot into Ubuntu.
Network Configuration
⚠️ After completing the system installation, it is recommended to immediately check the network environment to ensure it is functioning properly. This includes verifying IP configuration, DNS server availability, and the ability to connect to external networks. If the network connection is unstable or interrupted, it will severely affect subsequent package installations, remote management, and system maintenance.
|
|
You can find the wired network interface name (e.g., enp8s0) in the output as follows:
|
|
Since Ubuntu 17.10, network management has been unified under Netplan. You can check the configuration files located in /etc/netplan
using the following command. Common filenames include 01-netcfg.yaml
or 50-cloud-init.yaml
:
|
|
In Netplan configurations, 01-netcfg.yaml
has a higher priority. If this file exists, the system will apply its settings first. Currently, my server only contains the 50-cloud-init.yaml
configuration file, which can be edited using the following command:
|
|
In the file, you can apply the following configuration. This example sets enp8s0 to obtain an IP address automatically via DHCP and uses 1.1.1.1 and 8.8.8.8 as DNS servers. Adjust the settings according to your network environment:
|
|
If you need to set a static IP, you can use the following example and adjust the configuration according to your actual network segment:
|
|
After editing the configuration, apply the changes to the system using the following command:
|
|
Once the configuration is successfully applied, use the ping
command to test external network connectivity. For example:
|
|
The output will resemble the following message, indicating that the network is ready:
|
|
By following the above steps, you can confirm whether the network connection is functioning properly.
Ensure that the system’s software and packages are up to date
|
|
Remote Environment Setup
After securing network connectivity, the next crucial step is to configure remote access via Tailscale and SSH, ensuring a secure and efficient management experience.
Install Tailscale
For secure remote access to this machine, it is highly recommended to use Tailscale instead of exposing the server directly to the public internet.
For a detailed installation guide, refer to: Using Tailscale to Easily Create Secure and Private Tunnels.
|
|
After executing sudo tailscale up
. The terminal will display a URL. Open this URL using a web browser or a third-party device to log in to your Tailscale account. Once authentication is complete, the system will automatically add this device to your tailnet private network.
⚠️ Potential Issues After Installing Tailscale
After installing Tailscale, I encountered issues where the network interface name changed or DNS settings were overridden by Tailscale, preventing successful ping commands.
It is recommended to restart the system after installation and verify that the network connection is functioning properly. If necessary, update the network configuration accordingly.
Configure SSH
Refer to the following guide for more details: Using SSH Keys for Password-Free Remote Connections.
After completing the above configurations, you should be able to access and operate the system remotely using Tailscale + SSH from a third-party device.
System Basic Configuration and Installation
System Timezone and Language Settings
Use the following command to set the system timezone to Asia/Taipei:
|
|
For other regions, you can query all available timezones using timedatectl list-timezones
and filter the relevant timezone names using grep
, for example:
|
|
Execute the following command to generate the zh_TW.UTF-8
locale:
|
|
You can check the available locales on the system using locale -a
, which will output something like the following:
|
|
Use the update-locale
command to update the /etc/default/locale
file and set LANG
to zh_TW.UTF-8
:
|
|
Finally, check using the locale
command, and the output will be as follows:
|
|
The system’s default language and locale settings cover character encoding, time formats, number formats, currency formats, etc. Setting it to zh_TW.UTF-8
means the system will use Traditional Chinese (Taiwan) and UTF-8 encoding for character processing. The LANGUAGE
variable is used to specify the language priority, controlling the selection of the translation language. If this variable is empty, the system will rely solely on LANG
to set the language environment.
Install Net-tools
Net-tools
provides a set of useful network management and troubleshooting tools. However, since Ubuntu 18.10, this package is no longer installed by default, and some commands (such as ifconfig
and netstat
) have gradually been replaced by more modern tools like ip
and ss
.
If you still need to use Net-tools
, you can install it manually:
|
|
Install Build Essentials
Some development tools rely on compilers such as GCC, G++, and Make. It is recommended to install the build-essential
package to ensure a basic development and build environment.
|
|
Install ble.sh
ble.sh is a script that provides real-time syntax highlighting and powerful features (such as auto-completion) for Bash.
|
|
Install Homebrew
Homebrew provides a faster way to install software packages on macOS, allowing convenient installation, updates, and management of packages. It also supports other Linux systems like Ubuntu.
|
|
After installation, you will need to execute an additional two commands to automatically load Homebrew’s installation directory into Bash.
|
|
Install fzf
fzf is a command-line fuzzy finder tool that efficiently searches through files, command history, Git commits, and more using fuzzy search techniques. It significantly enhances developers’ productivity on the command line.
|
|
Install Node.js
Node.js is a JavaScript runtime environment used for both front-end and back-end development.
The official installation guide provides clear instructions. It is recommended to use nvm for installation.
|
|
Install tldr
tldr provides concise and practical command-line tool explanations and examples, offering a more intuitive alternative to the man
command on Linux.
|
|
To use tldr, simply type tldr <command>
.
|
|
Update Git to the Latest Version
Updating Git to the latest version is not always necessary. Some tools may require older versions of Git, and installing the latest version could lead to compatibility issues.
The git-core/ppa
is a Personal Package Archive (PPA) maintained by the Git community, providing the latest versions of Git software.
|
|
Configure Git User
To set up your Git user information, use the following commands:
|
|
Other Advanced Settings
Disable IPv6 Connection
If the ISP provides both IPv4 and IPv6 addresses, it is recommended to use only IPv4 for security or specific operational requirements. In this case, you can choose to disable IPv6 to ensure that all network traffic is transmitted exclusively over IPv4, thereby reducing the potential attack surface.
Disable IPv6 via sysctl
Before Ubuntu 17.10, network configuration was managed using traditional tools like ifupdown
and sysctl
, rather than Netplan. You can disable IPv6 using sysctl:
|
|
Add the following configurations at the end of the file and save the changes:
|
|
Apply the changes immediately by running:
|
|
Disable IPv6 via Netplan
Since Ubuntu 17.10, network management has been unified under Netplan. You can disable IPv6 for a specific network interface using Netplan:
|
|
Add link-local: [ ipv4 ]
to the configuration of the target network interface (e.g., enp8s0
). Below is an example configuration. Save the file and exit:
|
|
Verify the configuration and apply the settings:
|
|
Finally, verify that IPv6 has been successfully disabled by checking the network interface status with ip a
or ifconfig
. If the configuration was applied correctly, the interface should no longer display an inet6
address.
Set VS Code as the Default Editor for SSH Remote Development
When connecting to Ubuntu via SSH, you can set VS Code as the default editor, making the editing experience in the terminal more intuitive, and allowing you to open files directly using the code
command.
First, modify the .bashrc
file (if using zsh, modify ~/.zshrc
). Execute the following command to open .bashrc
in VS Code:
|
|
Next, add the following content at the bottom of the file to ensure the system uses VS Code as the default editor:
|
|
Once completed, save the file (Ctrl + S
) and close it.
Finally, execute the following command to reload the settings, or simply open a new terminal to apply the changes:
|
|
With this setup, you can easily edit files that require elevated privileges using sudoedit
in the terminal, opening and editing them directly in VS Code. Similarly, running crontab -e
to edit cron jobs will automatically open VS Code, making remote development smoother and more efficient.
Configure Ubuntu Pro Security
Enabling Ubuntu Pro allows for real-time system vulnerability fixes, enhancing system security and stability.
First, register and obtain a free Ubuntu Pro subscription from the Ubuntu official website. You can register at Ubuntu Pro.
After registration, subscribe to Ubuntu Pro using sudo pro attach <YOUR_TOKEN>
:
|
|
The output:
|
|
Conclusion
Once the above basic environment configurations are set up, you can happily proceed with remote development 🥳.
References
- What is a VPS (Virtual Private Server)?
- Ubuntu Server documentation
- DiskSpace - Community Help Wiki
- Ubuntu Bionic: Netplan
- ble.sh
- fzf
- tldr-pages/tldr
- First-Time Git Setup
- Use UFW to lock down an Ubuntu server
- networking - I have both IPv4 and IPv6 public addresses. Why?
- Fine-Tuning the Ubuntu 24.04 Kernel for low latency, throughput, and power efficiency