Skip to content

Enable SSH on a Linux Container (LXC)

Here is a quick guide to setting up SSH on a Linux Container (LXC) on Proxmox. If you’re using Proxmox, you’ll need to access the command line using the Proxmox console to enter these commands.

These steps assume SSH already installed on your LXC. If it’s not, you’ll need to install it first.

Step 1. Verify SSH is Installed and Running on Your Ubuntu LXC

Section titled “Step 1. Verify SSH is Installed and Running on Your Ubuntu LXC”
Terminal window
sudo systemctl status ssh

You’ll see some output either indicating that SSH is running or not running or, if it’s not installed. My system indicated it’s installed but not active.

Terminal window
root@Grafana-223:~# systemctl status ssh
* ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enable>
Active: inactive (dead)
Docs: man:sshd(8)
man:sshd_config(5)
Terminal window
sudo systemctl start ssh

Now when you run systemctl status ssh you should see that it’s active and running:

Terminal window
root@Grafana-223:~# systemctl start ssh
root@Grafana-223:~# systemctl status ssh
* ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enable>
Active: active (running) since Tue 2024-10-15 12:16:18 UTC; 4s ago
Docs: man:sshd(8)
man:sshd_config(5)
Process: 433 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
Main PID: 434 (sshd)
Tasks: 1 (limit: 9346)
Memory: 1.7M
CPU: 67ms
CGroup: /system.slice/ssh.service
`-434 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"
Oct 15 12:16:17 Grafana-223 systemd[1]: Starting OpenBSD Secure Shell server...
Oct 15 12:16:18 Grafana-223 sshd[434]: Server listening on 0.0.0.0 port 22.
Oct 15 12:16:18 Grafana-223 sshd[434]: Server listening on :: port 22.
Oct 15 12:16:18 Grafana-223 systemd[1]: Started OpenBSD Secure Shell server.
Terminal window
sudo systemctl enable ssh
  1. Open a terminal and do a quick ping to the IP address of the container to ensure it’s up and running.

    Terminal window
    ping <ip-address of container>
  2. SSH into the container.

    Terminal window
    ssh root@<ip-address of container>

    You’ll be prompted to enter the password for the root user and you should be able to access the container via SSH.

  1. If you’re still having issues, you may need to check the SSH configuration file on the container to ensure that SSH passwords are allowed. You can find it at /etc/ssh/sshd_config. These will still need to be done via the Proxmox console.

    Terminal window
    sudo nano /etc/ssh/sshd_config
  2. Look for the line PermitRootLogin and ensure it’s set to yes. If it’s set to no, change it to yes and save the file. My file had the line commented out with a value of prohibit-password. I uncommented the line and changed the value to yes.

    Terminal window
    PermitRootLogin yes
  3. Don’t forget to save and then restart the SSH service after making changes to the configuration file.

    Terminal window
    sudo systemctl restart ssh
Section titled “Step 5. Create a New User (Optional but Recommended)”

It’s generally not recommended to use the root user for SSH access. Instead, create a new user and give them sudo privileges.

  1. Create a new user.

    Terminal window
    adduser <username>
  2. Add the new user to the sudo group.

    Terminal window
    usermod -aG sudo <username>
  3. Switch to the new user.

    Terminal window
    su - <username>

And that’s it! You’ve enabled SSH on your Linux Container (LXC) on Proxmox. You can now access it via SSH.