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”sudo systemctl status sshYou’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.
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)Step 2. Start the SSH Service
Section titled “Step 2. Start the SSH Service”sudo systemctl start sshNow when you run systemctl status ssh you should see that it’s active and running:
root@Grafana-223:~# systemctl start sshroot@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.Step 3. Enable SSH to Start on Boot
Section titled “Step 3. Enable SSH to Start on Boot”sudo systemctl enable sshStep 4. Access the Container via SSH
Section titled “Step 4. Access the Container via SSH”-
Open a terminal and do a quick
pingto the IP address of the container to ensure it’s up and running.Terminal window ping <ip-address of container> -
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.
-
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 -
Look for the line
PermitRootLoginand ensure it’s set toyes. If it’s set tono, change it toyesand save the file. My file had the line commented out with a value ofprohibit-password. I uncommented the line and changed the value toyes.Terminal window PermitRootLogin yes -
Don’t forget to save and then restart the SSH service after making changes to the configuration file.
Terminal window sudo systemctl restart ssh
Step 5. Create a New User (Optional but Recommended)
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.
-
Create a new user.
Terminal window adduser <username> -
Add the new user to the sudo group.
Terminal window usermod -aG sudo <username> -
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.