Basic Linux Commands

May 1st 2023 — basic, command, linux, terminal

SSH Settings

This part is to manipulate ssh settings, see its status etc. Useful if just started a container in Proxmox

First, if SSH is not installed:

sudo apt-get update
sudo apt-get install openssh-server

Then manipulate 'sshd_config' file. If not added add lines below to prevent remote root login, allow remote password logging and set ssh port number(22 by default)

sudo nano /etc/ssh/sshd_config

Port 22
PermitRootLogin no
PasswordAuthentication yes

To see status of SSH, restart or stop it etc use codes below:

sudo systemctl status ssh
sudo systemctl start ssh
sudo systemctl restart ssh
sudo systemctl stop ssh

If ufw is running you may need to make it allow SSH

sudo ufw status
sudo ufw allow ssh

Alternate for not using 'root'

sudo nano /etc/ssh/sshd_config

then add this

PermitRootLogin no
PasswordAuthentication yes

and restart sshd service

sudo systemctl restart sshd

since you are not using root user, creata a user with sudo privileges 

SSH Settings

This section covers how to manipulate SSH settings, check its status, and make necessary adjustments. This is useful when you’ve just started a container in Proxmox.

Install SSH (if not installed)

If SSH is not installed on your system, use the following commands to install it:

sudo apt-get update
sudo apt-get install openssh-server

Configure SSH Settings

Once SSH is installed, you may need to modify the SSH configuration file (sshd_config) to enhance security and set your preferences. To edit the file, use:

sudo nano /etc/ssh/sshd_config

In the configuration file, make the following changes:

Disable root login over SSH (security measure):

PermitRootLogin no

Allow password-based authentication:

PasswordAuthentication yes

Set SSH port number (22 is the default, but you can change it if needed):

Port 22

Manage SSH Service

To check the status of the SSH service, restart it, or stop it, use the following commands:

Check SSH status:

sudo systemctl status ssh

Start SSH service:

sudo systemctl start ssh

Restart SSH service:

sudo systemctl restart ssh

Stop SSH service:

sudo systemctl stop ssh

Configure UFW Firewall for SSH

If you are using UFW (Uncomplicated Firewall), you may need to allow SSH traffic through the firewall:

Check UFW status:

sudo ufw status

Allow SSH traffic:

sudo ufw allow ssh

Alternate Configuration for Non-Root User Access

If you do not want to use the root user for SSH access, follow these steps:

Edit sshd_config file to disable root login and enable password authentication:

sudo nano /etc/ssh/sshd_config

Add or confirm the following lines:

PermitRootLogin no
PasswordAuthentication yes

Restart SSH service to apply the changes:

sudo systemctl restart sshd

Create a New User with Sudo Privileges

If you disabled root login, create a new user with sudo privileges:

Add a new user:

sudo adduser <username>

Grant the new user sudo privileges:

udo usermod -aG sudo <username>