Skip to content

SSH and ZeroTier on Ubuntu

Source: Notion | Last edited: 2025-04-25 | ID: 10c2d2dc-3ef...


This guide provides a step-by-step process to install and configure SSH and ZeroTier on an Ubuntu system. Whether you’re setting up a new server or enhancing an existing one, this tutorial ensures secure remote access and seamless network integration.

Before you begin, ensure you have the following:

  • Ubuntu Operating System: This guide is tailored for Ubuntu 20.04 LTS and later versions.
  • Sudo Privileges: Administrative access to install and configure services.
  • Terminal Access: Local or remote access via console or existing SSH session.

Secure Shell (SSH) allows you to remotely access and manage your Ubuntu system securely. This section covers installation, configuration for enhanced security, and setting up SSH key-based authentication.

First, install the OpenSSH server package.

Terminal window
sudo apt update
sudo apt install -y openssh-server

Verify SSH Service Status:

Terminal window
sudo systemctl status ssh

You should see output indicating that the SSH service is active and running.

Enhancing SSH security reduces the risk of unauthorized access.

Backup Original Configuration:

Terminal window
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup

Edit SSH Configuration:

Terminal window
sudo nano /etc/ssh/sshd_config

Recommended Changes:

  • Disable Root Login: Find the line:
Terminal window
#PermitRootLogin prohibit-password

Change to:

Terminal window
PermitRootLogin no
  • Change Default SSH Port (Optional): For added security through obscurity, you can change the default SSH port from 22 to another port (e.g., 2222).

    Find the line:

Terminal window
#Port 22

Change to:

Terminal window
Port 2222
  • Disable Password Authentication (After Setting Up SSH Keys): Find the line:
Terminal window
#PasswordAuthentication yes

Change to:

Terminal window
PasswordAuthentication no

Save and Exit:

Press CTRL + O to save and CTRL + X to exit.

Restart SSH Service to Apply Changes:

Terminal window
sudo systemctl restart ssh

SSH keys provide a more secure method of authentication compared to passwords.

Generate SSH Key Pair on Your Local Machine:

If you haven’t already generated an SSH key pair, do so on your local machine:

Terminal window
ssh-keygen -t ed25519 -C "your_email@example.com"

If you prefer RSA:

Terminal window
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Copy Public Key to Ubuntu Server:

Replace username and server_ip with your actual username and server IP address.

Terminal window
ssh-copy-id -p 2222 username@server_ip

If you changed the SSH port, include the -p flag with the new port.

Test SSH Login:

Terminal window
ssh -p 2222 username@server_ip

You should now be able to log in without a password.

Ensure that the firewall allows SSH connections.

Enable UFW:

Terminal window
sudo ufw enable

Allow SSH (Default Port 22):

Terminal window
sudo ufw allow ssh

If you changed the SSH port (e.g., 2222), allow the new port:

Terminal window
sudo ufw allow 2222/tcp

Allow ZeroTier (Handled Later):

We’ll configure ZeroTier access after installing it.

Check UFW Status:

Terminal window
sudo ufw status

ZeroTier provides a virtual network that can simplify network configurations and improve security. Follow these steps to install ZeroTier on your Ubuntu system.

Ensure your package list is up to date.

Terminal window
sudo apt update

Install curl and gnupg if they are not already installed.

Terminal window
sudo apt install -y curl gnupg

Import ZeroTier’s GPG key to verify the authenticity of the packages.

Terminal window
curl -s <https://pgp.zerotier.com/contact%40zerotier.com.gpg> | gpg --dearmor | sudo tee /usr/share/keyrings/zerotier-archive-keyring.gpg > /dev/null

Add ZeroTier’s repository to your system’s package sources.

Terminal window
echo "deb [signed-by=/usr/share/keyrings/zerotier-archive-keyring.gpg] <https://download.zerotier.com/debian/$>(lsb_release -cs) $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/zerotier.list

Refresh the package list to include ZeroTier’s repository.

Terminal window
sudo apt update

Install the ZeroTier One package.

Terminal window
sudo apt install -y zerotier-one

After installation, configure ZeroTier to join your desired network.

Start the ZeroTier service and enable it to start on boot.

Terminal window
sudo systemctl start zerotier-one
sudo systemctl enable zerotier-one

Verify Service Status:

Terminal window
sudo systemctl status zerotier-one

You should see that the service is active and running.

Join your specific ZeroTier network using the network ID.

Replace <network_id> with Your Actual Network ID:

Terminal window
sudo zerotier-cli join <network_id>

Verify Network Membership:

Terminal window
sudo zerotier-cli listnetworks

You should see your network listed with a status indicating whether it’s authorized.


Encountering issues during installation or configuration? Here are common problems and their solutions.

Symptoms:

  • Unable to connect via SSH.
  • Connection times out or is refused. Solutions:
  1. Check SSH Service Status:
Terminal window
sudo systemctl status ssh

Ensure the service is active.

  1. Verify Firewall Settings:
Terminal window
sudo ufw status

Ensure the SSH port is allowed.

  1. Confirm SSH Configuration: Revisit /etc/ssh/sshd_config to ensure settings are correct, especially if you changed the SSH port.

  2. Restart SSH Service:

Terminal window
sudo systemctl restart ssh
  1. Check Network Connectivity: Ensure your server is reachable from your local machine.

Symptoms:

After joining a network, the status shows ACCESS_DENIED or similar.

Solutions:

  1. Authorize the Device:
  • Log in to ZeroTier Central.
  • Navigate to your network.
  • Find the unauthorized device and authorize it.
  1. Wait for Propagation: Authorization might take a few minutes. Retry listing networks:
Terminal window
sudo zerotier-cli listnetworks

Symptoms:

Cannot find the ZeroTier network interface (e.g., zt0).

Solutions:

  1. List All Network Interfaces:
Terminal window
ip addr

Look for interfaces starting with zt followed by random characters (e.g., ztksetviym).

  1. Use Correct Interface Name: Reference the actual interface name when configuring network settings or scripts.

Symptoms:

ZeroTier service fails to start or behaves unexpectedly.

Solutions:

  1. Check Service Status:
Terminal window
sudo systemctl status zerotier-one
  1. View Service Logs:
Terminal window
sudo journalctl -u zerotier-one -e
  1. Restart the Service:
Terminal window
sudo systemctl restart zerotier-one
  1. Reinstall ZeroTier (if necessary):
Terminal window
sudo apt remove --purge zerotier-one
sudo apt install zerotier-one

Once SSH and ZeroTier are installed and configured:

  1. Verify SSH Access: Ensure you can connect to your server via SSH using your key-based authentication.
Terminal window
ssh -p 2222 username@server_ip
  1. Verify ZeroTier Network Membership:
Terminal window
sudo zerotier-cli listnetworks

Confirm that your device is listed and authorized.

  1. Check ZeroTier Interface: Identify your ZeroTier network interface and verify its IP address.
Terminal window
ip addr show zt*
  1. Configure Additional Services (Optional): If you’re setting up services that rely on ZeroTier for networking, configure them to use the ZeroTier interface.

By following this comprehensive guide, you’ve successfully installed and secured SSH on your Ubuntu system and integrated it into a ZeroTier network. This setup ensures secure remote access and flexible networking capabilities, enhancing both the security and functionality of your server environment.

Remember:

  • Regularly Update Your System: Keep your system and installed packages up to date to benefit from the latest security patches.
Terminal window
sudo apt update && sudo apt upgrade -y
  • Monitor Access Logs: Periodically review SSH and ZeroTier logs to monitor for any unauthorized access attempts.
Terminal window
sudo journalctl -u ssh
sudo journalctl -u zerotier-one
  • Backup Configuration Files: Maintain backups of your SSH and ZeroTier configurations to facilitate quick recovery in case of issues.
Terminal window
sudo cp /etc/ssh/sshd_config ~/sshd_config.backup
sudo cp /etc/zerotier-one/zerotier-one.conf ~/zerotier-one.conf.backup

With these practices, your Ubuntu server will remain secure, accessible, and well-integrated into your desired networks.