VS Code SSH Config Location:
-
Windows:
C:\Users\YourUsername\.ssh\config -
macOS/Linux:
~/.ssh/config
SSH Config Structure:
Host my-server
HostName 192.168.1.100
User myusername
Port 22
IdentityFile ~/.ssh/id_rsa
SSH Config Options:
# Simple connection
Host myserver
HostName 192.168.1.100
User admin
# Custom port
Host production
HostName prod.example.com
User deploy
Port 2222
# With identity file
Host github
HostName github.com
User git
IdentityFile ~/.ssh/github_rsa
# Jump host / Proxy
Host internal-server
HostName 10.0.0.5
User myuser
ProxyJump bastion-host
Host bastion-host
HostName bastion.example.com
User jumpuser
IdentityFile ~/.ssh/bastion_key
VS Code Specific Settings:
Add these to your VS Code settings.json:
json
{
"remote.SSH.showLoginTerminal": true,
"remote.SSH.configFile": "~/.ssh/config",
"remote.SSH.useLocalServer": false,
"remote.SSH.allowLocalServerDownload": true,
"remote.SSH.connectTimeout": 60,
"remote.SSH.serverInstallTimeout": 120
}
Using different keys for different platforms
Host aws-*
User ubuntu
IdentityFile ~/.ssh/aws-key.pem
IdentitiesOnly yes
Host aws-web
HostName ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com
Setting File Permissions
# Linux/macOS
chmod 600 ~/.ssh/config
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
VS Code Remote-SSH Commands
-
Connect:
Ctrl+Shift+P→ "Remote-SSH: Connect to Host..." -
Disconnect:
Ctrl+Shift+P→ "Remote-SSH: Close Remote Connection" -
Reopen:
Ctrl+Shift+P→ "Remote-SSH: Reopen in Remote Window" -
Create SSH config:
touch ~/.ssh/config
chmod 600 ~/.ssh/config
-
Add your server:
-
ssh-config
Host dev HostName dev.company.com User johndoe IdentityFile ~/.ssh/id_rsa
Generate SSH Key Pair
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
ssh-keygen -t rsa -b 4096
Verify Generated Keys
# Check if keys were created
ls -la ~/.ssh/id_rsa*
-
~/.ssh/id_rsa- PRIVATE KEY (keep secret!) -
~/.ssh/id_rsa.pub- PUBLIC KEY (share with servers)
Set Correct Permissions
chmod 600 ~/.ssh/id_rsa # Private key - read/write for owner only
chmod 644 ~/.ssh/id_rsa.pub # Public key - readable by everyone
chmod 700 ~/.ssh # .ssh directory
Alternative Key Types
# ED25519 (faster, more secure, recommended for modern systems)
ssh-keygen -t ed25519 -C "your_email@example.com"
# ECDSA (smaller key size)
ssh-keygen -t ecdsa -b 521 -C "your_email@example.com"
# RSA 2048 (older, still widely supported)
ssh-keygen -t rsa -b 2048 -C "your_email@example.com"
Copy Public Key to Server
Method 1: Using ssh-copy-id (Recommended)
bash
ssh-copy-id user@your-server.com
Method 2: Manual copy
bash
# View and copy the public key
cat ~/.ssh/id_rsa.pub
# Then on the server, add to authorized_keys
echo "ssh-rsa AAAAB3NzaC1yc2E..." >> ~/.ssh/authorized_keys
Quick One-Liner Setup
# Generate key and copy to server in one go
ssh-keygen -t rsa -b 4096 -C "your_email@example.com" -f ~/.ssh/id_rsa -N "" && ssh-copy-id user@server.com
Test Your SSH Connection
# Test with verbose output
ssh -v user@your-server.com
# Test with the key explicitly
ssh -i ~/.ssh/id_rsa user@your-server.com
Issue: "Permission denied (publickey)"
# Check key permissions
chmod 600 ~/.ssh/id_rsa
# Ensure public key is on server
cat ~/.ssh/id_rsa.pub
# Copy output to server's ~/.ssh/authorized_keys
Issue: "No such file or directory"
# Create .ssh directory if it doesn't exist
mkdir -p ~/.ssh
chmod 700 ~/.ssh
-
Check SSH service is running on server:
# On the server
sudo systemctl status sshd
# or
sudo service ssh status
-
Enable password authentication on server:
# On the server
sudo nano /etc/ssh/sshd_config
# Make sure these lines are set:
PasswordAuthentication yes
# Restart SSH
sudo systemctl restart sshd
-
Test manually first:
# From your terminal
ssh admin@192.168.1.50
# Enter password
# Connect with password first
ssh username@192.168.1.100
# Once connected, check SSH config
sudo nano /etc/ssh/sshd_config
# Make sure these lines are set:
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication yes # Keep this until key works
# Restart SSH
sudo systemctl restart sshd
# or
sudo service ssh restart
# 1. View your public key
cat ~/.ssh/id_rsa.pub
# 2. Copy the output (starts with ssh-rsa AAAAB3...)
# 3. Connect to server with password
ssh username@192.168.1.100
# 4. On the server, create/update authorized_keys
mkdir -p ~/.ssh
chmod 700 ~/.ssh
echo "ssh-rsa AAAAB3..." >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
exit
# 5. Test passwordless login
ssh username@192.168.1.100
nano ~/.ssh/config
- Check your IP address:
# On Mac
ifconfig | grep inet
# On Windows
ipconfig
# On Linux
ip addr show
# Test if port 22 is open
nc -zv 192.168.50.122 22
# or
telnet 192.168.50.122 22
-
On the server, check firewall:
-
bash
# Linux (UFW) sudo ufw status sudo ufw allow 22 # Linux (firewalld) sudo firewall-cmd --list-all sudo firewall-cmd --add-service=ssh # iptables sudo iptables -L -n
sudo systemctl status sshd
# or
sudo service ssh status
# 1. Ping test
ping -c 4 192.168.50.122
# 2. Traceroute to see where it fails
traceroute 192.168.50.122
# or
tracert 192.168.50.122 # Windows
# Check if SSH port is open
nmap -p 22 192.168.50.122
# or
nc -zv 192.168.50.122 22
# Show routing table
netstat -rn
# or
route -n