DEV Community

Vlyth_r
Vlyth_r

Posted on • Edited on

Turn Your Old Laptop or PC into Your Own Private Server

Repurposing an old PC or laptop as a private server offers several benefits:

  • It allows you to extend the lifespan of your aging hardware, giving it a new purpose and avoiding unnecessary e-waste.
  • You can host websites, share files, run services, or experiment with various server applications.
  • It offers a valuable learning opportunity, allowing you to gain hands-on experience in server administration, networking, and software configuration.

Overall, repurposing an old PC or laptop as a private server is an eco-friendly, budget-friendly solution, and a great educational project.

Here's one way you can do it:

Step 1: Choose a Linux Distribution

For repurposing your old laptop or PC as a server, I recommend using a lightweight and resource-efficient Linux distribution. Lubuntu, Xubuntu, or Ubuntu Server are good options. In this tutorial, we'll use Lubuntu, which is known for its low system requirements and user-friendly interface.

Step 2: Obtain Lubuntu ISO

Visit the official Lubuntu website (https://lubuntu.me/downloads/) and download the latest stable version of Lubuntu. Make sure to choose the 64-bit (x64) version if your old laptop or PC supports it.

Step 3: Create a Bootable USB Drive

To install Lubuntu on your old laptop or PC, you'll need to create a bootable USB drive. Follow these steps:

3.1 Insert a USB drive with a minimum capacity of 4GB into your computer.
3.2 Download and install a tool like Rufus (https://rufus.ie/) or balenaEtcher (https://www.balena.io/etcher/) to create the bootable USB drive.
3.3 Open the tool and select the ISO file you downloaded in Step 2.
3.4 Choose the USB drive as the destination and start the process. This will format the USB drive and make it bootable. Wait for the process to complete, and you'll have a bootable USB drive with Lubuntu.

Step 4: Install Lubuntu

Now it's time to install Lubuntu on your old laptop or PC. Follow these steps:

4.1 Insert the bootable USB drive into the old laptop or PC and boot from it. You may need to access the BIOS settings and change the boot order to prioritize the USB drive.
4.2 Choose the appropriate language and select "Install Lubuntu" from the menu.
4.3 Select your preferred language, keyboard layout, and other regional settings.
4.4 If prompted, choose the option to install third-party software for graphics and Wi-Fi hardware.
4.5 Select the "Erase disk and install Lubuntu" option for a clean installation. Alternatively, choose the "Something else" option if you want to customize the partitioning.
4.6 Follow the on-screen instructions to set up your username, password, and other basic settings.
4.7 Wait for the installation process to complete. Once finished, reboot your old laptop or PC.

Step 5: Update and Upgrade

After the installation, it's important to update and upgrade the system to ensure you have the latest software versions and security patches. Open a terminal and run the following commands:

sudo apt update
sudo apt upgrade
Enter fullscreen mode Exit fullscreen mode

Step 6: Install and Configure Services

Now that Lubuntu is installed, you can set up various services and applications to turn your old laptop or PC into a private server. Here are a few examples:

6.1 SSH Server: Install OpenSSH server to remotely access your server:

sudo apt install openssh-server
Enter fullscreen mode Exit fullscreen mode

6.1.1 Configure SSH Server: Once the OpenSSH server is installed, you can proceed to configure it to meet your requirements:

6.1.2 Open the SSH server configuration file using a text editor. In this example, we'll use the Nano editor:

sudo nano /etc/ssh/sshd_config
Enter fullscreen mode Exit fullscreen mode

6.1.3 Within the configuration file, you'll find various settings that you can modify. Some commonly modified settings include:

  • Port: By default, SSH uses port 22. If you want to use a different port, locate the line that says #Port 22 (commented out) and change it to your desired port number. Uncomment the line by removing the '#' character and replace '22' with the desired port number.

  • PermitRootLogin: By default, root login is disabled for security reasons. If you want to enable root login, locate the line that says #PermitRootLogin prohibit-password and change it to PermitRootLogin yes.

  • PasswordAuthentication: By default, SSH uses key-based authentication. If you want to allow password authentication, locate the line that says #PasswordAuthentication yes and change it to PasswordAuthentication yes.

  • AllowUsers: If you want to restrict SSH access to specific users, you can use the AllowUsers directive. Uncomment the line that says #AllowUsers username and replace 'username' with the desired username. You can add multiple usernames separated by a space.

6.1.4 After making the necessary changes, save the file and exit the text editor. In Nano, you can do this by pressing Ctrl + X, then Y, and finally Enter to confirm the filename.

6.1.5 To apply the changes, restart the SSH service by running the following command:

sudo systemctl restart sshd
Enter fullscreen mode Exit fullscreen mode

6.2 Web Server: Install Apache to host websites:

sudo apt install apache2
Enter fullscreen mode Exit fullscreen mode

Once the installation is complete, Apache will automatically start running on your system. You can verify the status of the Apache service by running the following command:

sudo systemctl status apache2
Enter fullscreen mode Exit fullscreen mode

6.3 Database Server: Install MySQL or MariaDB for database functionality:

6.3.1 Open the terminal on your Lubuntu system.

6.3.2 Run the following command to install the MySQL server:

sudo apt install mysql-server
Enter fullscreen mode Exit fullscreen mode

6.3.3 During the installation process, you may be prompted to enter your password. Provide the password and press Enter to proceed.

6.3.4 The package manager will download and install MySQL server and its dependencies. This may take a moment.

6.3.5 Once the installation is complete, MySQL server will automatically start running on your system.

6.3.6 To enhance the security of your MySQL installation, it is recommended to run the security script provided by MySQL. This script will guide you through securing the installation and setting a root password. Run the following command to start the script:

sudo mysql_secure_installation
Enter fullscreen mode Exit fullscreen mode

6.3.7 The script will prompt you with several security-related questions. You can choose the default options or follow the prompts to configure MySQL according to your preferences. It is recommended to at least set a strong password for the root user.

6.3.8 After completing the security script, you can verify the status of the MySQL service by running the following command:

sudo systemctl status mysql
Enter fullscreen mode Exit fullscreen mode

If MySQL is running correctly, you should see a message indicating that the service is active and running.

6.4 File Server: Set up Samba for file sharing with other devices on your network:

6.4.1 Open the terminal on your Lubuntu system.

6.4.2 Run the following command to install the Samba package:

sudo apt install samba
Enter fullscreen mode Exit fullscreen mode

6.4.3 During the installation process, you may be prompted to enter your password. Provide the password and press Enter to proceed.

6.4.4 The package manager will download and install Samba and its dependencies. This may take a moment.

6.4.5 Once the installation is complete, Samba will be ready to configure for file sharing.

6.4.6 By default, Samba creates a special user called smbuser. You need to create a password for this user to access the shared files. Run the following command and set a password when prompted:

sudo smbpasswd -a smbuser
Enter fullscreen mode Exit fullscreen mode

6.4.7 Next, you need to configure the shared directories. Open the Samba configuration file in a text editor by running the following command:

sudo nano /etc/samba/smb.conf
Enter fullscreen mode Exit fullscreen mode

6.4.8 Within the configuration file, you will find the [global] section, which contains various settings for Samba. Below the [global] section, you can define the shared directories. Each shared directory is defined with a separate section. For example, to share a directory named "SharedFolder", add the following lines at the end of the file:

[SharedFolder]
   path = /path/to/shared/folder
   writable = yes
   guest ok = no
   read only = no
   create mask = 0777
   directory mask = 0777
Enter fullscreen mode Exit fullscreen mode

Replace /path/to/shared/folder with the actual path to the directory you want to share.

6.4.9 Save the file and exit the text editor by pressing Ctrl + X, then Y, and finally Enter.

6.4.10 To apply the changes, restart the Samba service by running the following command:

sudo systemctl restart smbd
Enter fullscreen mode Exit fullscreen mode

6.4.11 Now, you should be able to access the shared folder from other devices on your network by using the IP address of your Lubuntu system. For example, if the IP address of your Lubuntu system is 192.168.1.100, you can access the shared folder by entering \\192.168.1.100\SharedFolder in the file explorer of another device.

Step 7: Configure Firewall

To enhance security, it's crucial to configure a firewall to control incoming and outgoing network traffic. Lubuntu uses UFW (Uncomplicated Firewall) by default. Use the following steps to set up and configure UFW:

7.1 Check the UFW status to see if it's enabled:

sudo ufw status
Enter fullscreen mode Exit fullscreen mode

7.2 By default, UFW denies all incoming connections. Allow SSH access by running:

sudo ufw allow OpenSSH
Enter fullscreen mode Exit fullscreen mode

7.3 Enable UFW to start at boot:

sudo ufw enable
Enter fullscreen mode Exit fullscreen mode

7.4 Confirm the firewall status and rules:

sudo ufw status verbose
Enter fullscreen mode Exit fullscreen mode

Step 8: Additional Configurations

Depending on your requirements, you may want to perform additional configurations and install specific software on your private server. Some examples include setting up a DNS server, configuring a VPN, or installing a media server like Plex. Consult relevant documentation or online resources for detailed instructions on these specific configurations.

You can now customize it further by installing additional software and services based on your needs.

Remember to keep your server regularly updated, apply security patches, and follow best practices to ensure a secure and reliable server environment.

Top comments (2)

Collapse
 
lkp profile image
Lâm Kim Phú

Thanks for sharing. About distro, in this case I suggest to install Ubuntu Server instead of Lubuntu because we don't need GUI for a server.

Collapse
 
robchal31 profile image
Robbany Chalif A

thanks for sharing