
SSH (Secure Shell) is an encrypted protocol for connecting to a server remotely. When you rent a VPS you get no screen or mouse — you command everything through a command line connected over SSH, whether installing software, configuring services, or managing files. This guide explains how to connect over SSH from both Windows and macOS, along with how to set it up securely.
What You Need Before Connecting
- IP Address of your VPS (provided in the welcome email after purchase)
- Username: typically
rootfor Linux VPS - Password or SSH private key
- Port: default is
22
Connect from Windows (Method 1: PuTTY)
- Download PuTTY from putty.org
- Open PuTTY → enter your VPS IP in the Host Name field
- Port: 22, Connection type: SSH
- Click Open → click Yes on the security alert (first time only)
- Login as:
root→ enter your password
Connect from Windows (Method 2: Windows Terminal)
Windows 10 and 11 include a built-in SSH client. Open Command Prompt or PowerShell and type:
ssh root@YOUR_VPS_IP
Enter your password when prompted.
Connect from macOS or Linux
Open Terminal (macOS: Cmd+Space, type Terminal) and run:
ssh root@YOUR_VPS_IP
To connect using an SSH key:
ssh -i /path/to/private_key root@YOUR_VPS_IP
Essential Commands After Logging In
ls -la— list files and directoriespwd— show current directorycd /var/www/html— change to a directoryapt update && apt upgrade— update system packages (Ubuntu/Debian)df -h— check disk usagefree -h— check RAM usageexit— end the SSH session
Improve Security: Change the SSH Port
Changing from port 22 reduces automated bot scanning:
nano /etc/ssh/sshd_config
Find the line #Port 22 → change it to Port 2222 (or any unused port) → restart SSH: systemctl restart sshd
Best practice: Avoid using root for routine tasks. Create a regular user and add it to the sudo group instead: adduser myuser then usermod -aG sudo myuser. Log in as that user for daily work.
Setting Up SSH Key Authentication
SSH key authentication replaces passwords with a cryptographic key pair: a private key stored only on your local machine and a public key uploaded to your VPS. Every connection is verified automatically without typing a password — and without exposing credentials that could be intercepted.
Generate an SSH Key Pair
Run the following on your local machine (Windows Terminal, macOS Terminal, or Linux):
ssh-keygen -t ed25519 -C "[email protected]"
You will be asked where to save the file and whether to set a passphrase (strongly recommended). This creates two files:
~/.ssh/id_ed25519— Your private key (never share this)~/.ssh/id_ed25519.pub— Your public key (uploaded to the VPS)
Copy the Public Key to Your VPS
# Using ssh-copy-id (macOS / Linux)
ssh-copy-id -i ~/.ssh/id_ed25519.pub root@YOUR_VPS_IP
# Manual method
cat ~/.ssh/id_ed25519.pub | ssh root@YOUR_VPS_IP \
"mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
Test the key login first, then disable password authentication by setting PasswordAuthentication no in /etc/ssh/sshd_config and restarting SSH.
Configuring UFW Firewall Alongside SSH
A firewall is the first line of defence for any VPS. UFW (Uncomplicated Firewall) makes it simple to allow only the ports you need. The most critical step is allowing SSH before enabling UFW — otherwise you will lock yourself out.
# Install UFW (if not already present)
apt install ufw -y
# Allow SSH first (CRITICAL — do this before enabling)
ufw allow 22/tcp
# Allow web server ports
ufw allow 80/tcp
ufw allow 443/tcp
# Enable the firewall
ufw enable
# Check status
ufw status verbose
| Service | Port | UFW Command | Note |
|---|---|---|---|
| SSH | 22 | ufw allow 22/tcp | Must allow before enable |
| HTTP | 80 | ufw allow 80/tcp | Web traffic |
| HTTPS | 443 | ufw allow 443/tcp | SSL/TLS traffic |
| MySQL | 3306 | ufw deny 3306 | Keep private, use SSH tunnel |
Transferring Files Over SSH: SCP and SFTP
SSH is not just for terminal sessions — it also powers two secure file transfer protocols: SCP (Secure Copy) for quick command-line transfers, and SFTP (SSH File Transfer Protocol) for interactive file management. Both encrypt everything in transit over the same SSH channel you already have open.
SCP — Quick Command-Line Transfers
# Upload a file from your machine to the VPS
scp /path/to/local/file.zip root@YOUR_VPS_IP:/var/www/html/
# Download a file from the VPS to your machine
scp root@YOUR_VPS_IP:/var/log/nginx/error.log ~/Downloads/
# Copy an entire directory (use -r flag)
scp -r root@YOUR_VPS_IP:/var/www/html/mysite ~/backup/
SFTP — Interactive File Management
Start an SFTP session with:
sftp root@YOUR_VPS_IP
Inside the SFTP shell: ls lists remote files, lls lists local files, put file.txt uploads, get file.txt downloads, and exit ends the session. GUI clients like FileZilla and Cyberduck support SFTP with a drag-and-drop interface.
Monitoring SSH Sessions and Security Logs
Regularly reviewing SSH logs tells you whether unauthorised login attempts are happening. Servers with port 22 open on the public internet constantly receive automated scanning and brute-force attempts from botnets around the world — even brand-new servers.
# Show last 20 successful logins
last -n 20
# Show failed login attempts (Ubuntu / Debian)
grep "Failed password" /var/log/auth.log | tail -30
# Show failed login attempts (CentOS / AlmaLinux)
grep "Failed password" /var/log/secure | tail -30
# Show currently connected sessions
who
# View SSH daemon log via journald
journalctl -u sshd -n 50 --no-pager
| Log File | OS | Contents |
|---|---|---|
| /var/log/auth.log | Ubuntu / Debian | SSH logins, sudo, PAM |
| /var/log/secure | CentOS / AlmaLinux | SSH logins, sudo, su |
| journalctl -u sshd | Any systemd distro | Detailed SSH daemon events |
If you see repeated failed attempts from the same IP address, consider installing Fail2ban to automatically block offending IPs, or block them manually with ufw deny from BAD_IP_ADDRESS.
Frequently Asked Questions
How is an SSH key safer than a password?
An SSH key uses a long, unguessable key pair, unlike a password that can be guessed or brute-forced. Once a key is set up, disable password login for maximum security.
Do I need to install software to use SSH from Windows?
Modern Windows includes the ssh command in Command Prompt and PowerShell. Tools like PuTTY are an alternative with a graphical interface for managing connections.
What port does SSH use, and can I change it?
The default is port 22. You can change it to reduce random attacks, but do so alongside SSH keys and a firewall — don't rely on changing the port alone.
Need an Affordable Linux VPS?
AsiaGB Linux VPS starts from 750 THB/month — full root access, dedicated IP in Thailand and Singapore.
View VPS Plans