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.

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-server

Check the SSH Service

Ensure SSH is running:

sudo systemctl status ssh

If it’s not, start and enable it:

sudo systemctl start ssh
sudo systemctl enable ssh

Find the IP Address

To connect via SSH, find the IP address of your machine:

ip a

Look for something like 192.168.x.x under your network interface.

Connect from Another Machine

Use this command:

ssh username@ip_address

Replace 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 ufw

Allow SSH Before Enabling UFW

This prevents locking yourself out:

sudo ufw allow ssh

Enable UFW

sudo ufw enable

Check Status

sudo ufw status

Now, 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.conf

Change or add the following lines:

HandleLidSwitch=ignore
HandleLidSwitchDocked=ignore
HandleLidSwitchExternalPower=ignore

Then restart the login daemon:

sudo systemctl restart systemd-logind

This 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-keygen

Press 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_address

After 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_address

If everything is set up correctly, you won’t be prompted for a password.


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_config

Update or add the following lines:

PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM no

Save and exit, then restart the SSH service:

sudo systemctl restart ssh

Test

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.