Linux SSH Configuration

This note summarizes the SSH setup workflow after a new machine goes online. Follow the steps to complete basic remote login and permission settings.

1. Install the SSH Service and Basic Tools

sudo apt update
sudo apt install -y openssh-server
sudo apt install -y net-tools # Optional

# Start SSH
sudo service ssh start
# Enable SSH at boot
sudo systemctl enable ssh
# Check service status
sudo service ssh status

sudo apt install iputils-ping # Optional
passwd root # Optional: set a new root password

sudo nano /etc/ssh/sshd_config # Edit the config file

Change #PermitRootLogin prohibit-password to PermitRootLogin yes, then press Ctrl+S to save and Ctrl+X to exit.

2. Generate Keys and Write to the Authorized Keys File

ssh-keygen
nano ~/.ssh/authorized_keys

Open the public key file with a text editor, copy the public key content into authorized_keys, then press Ctrl+S to save and Ctrl+X to exit.

3. Fix Permissions for the SSH Directory and Authorized Keys File

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

4. Restart the SSH Service

sudo systemctl restart ssh

5. Check SSH Service Status

sudo systemctl status ssh