Connect via SSH
Learn how to securely connect to your VPS using SSH. Complete guide to key authentication, configuration, and troubleshooting.
- Active VPS with SSH service running
- SSH client installed on your local machine
- VPS IP address or domain name
- Valid username and password or SSH keys
SSH (Secure Shell) is the standard protocol for securely connecting to remote servers. It provides encrypted communication and authentication between your local machine and the VPS.
Why SSH?
- Encrypted connection prevents eavesdropping
- Secure authentication methods
- Works on all major operating systems
- Supports file transfers and tunneling
# Check if SSH is installed
ssh -V
# On Windows, you might need to use:
# PowerShell: Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
# Or install OpenSSH client from Microsoft StoreThe simplest way to connect is using password authentication. This method requires you to enter your VPS password each time you connect.
Basic Connection:
- Replace
your-usernamewith your actual username - Replace
your-server-ipwith your VPS IP address - You'll be prompted for your password
# Basic SSH connection with password
ssh your-username@your-server-ip
# Specify a different port (if not using default 22)
ssh -p 2222 your-username@your-server-ip
# Connect with verbose output (for troubleshooting)
ssh -v your-username@your-server-ipSSH key authentication is more secure than passwords and allows for passwordless login. This is the recommended method for production servers.
Key Benefits:
- No passwords to remember or type
- More secure than password authentication
- Supports automation and scripts
- Keys can be password-protected for extra security
# Generate SSH key pair (on your local machine)
ssh-keygen -t rsa -b 4096 -C "your-email@example.com"
# Press Enter for default location
# Optional: Add a passphrase for extra security
# Copy public key to your server
ssh-copy-id your-username@your-server-ip
# Alternative method - manual copy
cat ~/.ssh/id_rsa.pub
# Copy the output and paste it to ~/.ssh/authorized_keys on serverYou can customize SSH behavior using configuration files. This allows you to set default options, aliases, and security settings.
Configuration Files:
- ~/.ssh/config - User-specific configuration
- /etc/ssh/sshd_config - Server configuration
- ~/.ssh/known_hosts - Known host keys
# Create SSH config file
nano ~/.ssh/config
# Add server configuration
Host myserver
HostName your-server-ip
User your-username
Port 22
IdentityFile ~/.ssh/id_rsa
# Now you can connect with:
ssh myserver
# Server-side security (run on your VPS)
sudo nano /etc/ssh/sshd_config
# Recommended security settings:
# Port 22 (change to custom port)
# PermitRootLogin no
# PasswordAuthentication no
# PubkeyAuthentication yes
# MaxAuthTries 3
sudo systemctl reload sshdSSH offers many advanced features for power users and administrators. These features can improve productivity and security.
Useful Features:
- Port forwarding - Tunnel traffic through SSH
- SCP/SFTP - Secure file transfers
- SSH agent - Manage multiple keys
- X11 forwarding - Run GUI applications remotely
# Port forwarding examples
# Local port forwarding (access remote service locally)
ssh -L 8080:localhost:80 your-username@your-server-ip
# Remote port forwarding (expose local service remotely)
ssh -R 8080:localhost:3000 your-username@your-server-ip
# File transfer with SCP
scp file.txt your-username@your-server-ip:/path/to/destination/
scp your-username@your-server-ip:/path/to/file ./local/destination/
# SFTP for interactive file transfer
sftp your-username@your-server-ip
# SSH agent for managing keys
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
# Run command remotely without interactive shell
ssh your-username@your-server-ip "sudo apt update && sudo apt upgrade -y"Common SSH connection issues and their solutions. Most problems can be resolved with these troubleshooting steps.
Common Issues:
- Connection refused or timeout
- Permission denied errors
- Host key verification failed
- Port already in use
# Check SSH service status on server
sudo systemctl status sshd
sudo systemctl enable sshd
sudo systemctl start sshd
# Test connection with verbose output
ssh -v your-username@your-server-ip
# Clear known hosts (if host key changed)
ssh-keygen -R your-server-ip
# Check firewall settings
sudo ufw status
sudo ufw allow ssh
# Check SSH port
sudo netstat -tlnp | grep :22
sudo ss -tlnp | grep :22
# Test from another location (to rule out network issues)
ssh -T your-username@your-server-ipCan't find what you're looking for? Our support team is here to help.
