Skip to content

Instantly share code, notes, and snippets.

@timsonner
Created May 18, 2025 18:22
Show Gist options
  • Select an option

  • Save timsonner/42785f3ddd9bc710f1b86364165a5e26 to your computer and use it in GitHub Desktop.

Select an option

Save timsonner/42785f3ddd9bc710f1b86364165a5e26 to your computer and use it in GitHub Desktop.
Linux SSH server setup and key pair generation

Linux SSH server setup and key pair generation

SSH server setup

# Install SSH server
apt install openssh-server
# Enable SSH server on startup
systemctl enable ssh
# Check SSH server status
systemctl status ssh
# Allow SSH through firewall
ufw allow ssh
# Modify SSH config (optional)
nano /etc/ssh/sshd_config
systemctl restart ssh

Method 1 (SSH Copy)

Client - Generate public/private key pair

# Generate public/private key pair
ssh-keygen -t ed25519 -f <KEY PAIR NAME> -C "<COMMENT>"
# Copy public key to server
ssh-copy-id -i <PUBLIC KEY NAME>.pub <USERNAME>@<SERVER ADDRESS>
# Connect to server
ssh <USERNAME>@<SERVER ADDRESS>

Method 2 (Copy/Paste)

Client - Copy public key to clipboard

# Generate public/private key pair
ssh-keygen -t ed25519 -f <KEY PAIR NAME> -C "<COMMENT>"
# Display contents of public key on client. Copy to clipboard.  
cat <PUBLIC KEY NAME GOES HERE>.pub 

Server - Paste public key into authorized keys file

# Create .ssh directory if not already created
mkdir -p ~/.ssh
# Set permissions of .ssh directory
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
# Open authorized keys file in text editor and paste clipboard 
nano ~/.ssh/authorized_keys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment