· Home-server · 3 min read
How to Turn Your Ubuntu Desktop into a Remote-Accessible Server
Have an old laptop or desktop running Ubuntu? Turn it into a reliable home server or development box by enabling SSH, configuring firewall rules, keeping it awake with the lid closed, and securing access with key-based login. This guide walks you through the essential steps.
Have an old laptop or desktop running Ubuntu? Turn it into a reliable home server or development box by enabling SSH, configuring firewall rules, keeping it awake with the lid closed, and securing access with key-based login. This guide walks you through the essential steps.
1. Install and Enable SSH on Ubuntu Desktop
Ubuntu Desktop doesn’t come with SSH pre-installed. To access your machine remotely, you’ll need to install and enable the SSH server.
Install OpenSSH Server
Open a terminal and run:
sudo apt update
sudo apt install openssh-serverCheck the SSH Service
Ensure SSH is running:
sudo systemctl status sshIf it’s not, start and enable it:
sudo systemctl start ssh
sudo systemctl enable sshFind the IP Address
To connect via SSH, find the IP address of your machine:
ip aLook for something like 192.168.x.x under your network interface.
Connect from Another Machine
Use this command:
ssh username@ip_addressReplace username with your Ubuntu login and ip_address with the one you found above.
2. Enable UFW and Allow SSH
The Uncomplicated Firewall (UFW) is a simple way to manage iptables-based firewall rules.
Install UFW
sudo apt install ufwAllow SSH Before Enabling UFW
This prevents locking yourself out:
sudo ufw allow sshEnable UFW
sudo ufw enableCheck Status
sudo ufw statusNow, your firewall is active and SSH is allowed.
3. Prevent Sleep When Laptop Lid is Closed
If you’re using a laptop (e.g., as a home server), you probably don’t want it to sleep when the lid is closed.
Edit logind.conf
Run:
sudo nano /etc/systemd/logind.confChange or add the following lines:
HandleLidSwitch=ignore
HandleLidSwitchDocked=ignore
HandleLidSwitchExternalPower=ignoreThen restart the login daemon:
sudo systemctl restart systemd-logindThis may log you out — save any work first.
4. Set Up SSH Key Authentication
Using SSH keys instead of passwords makes your server more secure and convenient to access.
Generate an SSH Key Pair (on your client machine)
If you don’t already have a key:
ssh-keygenPress Enter to accept the default file location (~/.ssh/id_rsa) and leave the passphrase empty (or set one for more security).
Copy Your Public Key to the Server
Use ssh-copy-id to send your public key to the server:
ssh-copy-id username@ip_addressAfter entering your password once, your public key will be added to the server’s ~/.ssh/authorized_keys file.
Test Key-Based Login
Try logging in again:
ssh username@ip_addressIf everything is set up correctly, you won’t be prompted for a password.
5. Disable Password Login for SSH (Optional but Recommended)
Once key-based login is confirmed working, you can disable password login entirely to improve security.
Edit SSH Configuration
Open the SSH config file on the server:
sudo nano /etc/ssh/sshd_configUpdate or add the following lines:
PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM noSave and exit, then restart the SSH service:
sudo systemctl restart sshTest
Try connecting from another terminal or device. It should now only allow SSH logins using your key.
Wrap-Up
By combining these steps, you now have:
- SSH access to your Ubuntu Desktop
- Firewall protection with UFW
- A laptop that doesn’t sleep when the lid is closed
- Secure key-based authentication
- Password login disabled for better security
You’ve effectively transformed your Ubuntu Desktop or laptop into a lightweight and secure home server.