How to enable SSH on a Proxmox LXC (Linux Container)
In a LXC, SSH by default is turned off and all traffic through port 22 is disabled by the firewall so these two properties need to be enabled to SSH into an LXC.
First run the below command. This should tell you whether the SSH server is running. The result if the server is enabled should look like the below.
systemctl status ssh
If the SSH server is not enabled, run the below command.
service ssh startIt's important that the SSH server is started when the LXC is rebooted. Run the below command to enable this.
systemctl enable sshNext the firewall rules need updating. If you are using ufw enter the below command to allow traffic through port 22. Run the status command to see if the rules have been updated.
ufw allow sshufw status
To access this server a user needs to be created. You should avoid logging in or using the root user because from a security standpoint this is not safe for multiple reasons. For example, bots scan the internet for an open SSH port and they will try brute forcing login attempts with the root user. If they succeed, they have access to all the data in your LXC! Think of it this way, root is like having the master key to everything, always in the lock. Sudo is like having the key in your pocket and only using it when you need to open a specific door.
To create a new user and to give it sudo permissions enter the commands below. When running the first command it will prompt you to enter a password. Make sure you save this somewhere. It will also ask you for some other details which you can ignore by hitting return/enter.
adduser replacemeusermod -aG sudo replacemeAll done. You should now be able to SSH into your server from a Windows or Mac with the below command
ssh [email protected]Happy homelabbing!!