Skip to content

SSH Keys to Remote Linux (No Need to type password again!!!)

Source: Notion | Last edited: 2024-11-19 | ID: 1382d2dc-3ef...


This guide helps developers set up secure SSH connections for remote development, enabling seamless interaction with remote Linux servers through modern IDEs like VS Code or Cursor IDE.

  • Local Machine:
    • Windows/MacOS/Linux operating system
    • VS Code or Cursor IDE installed
    • Terminal access
    • Git (optional but recommended)
  • Remote Server:
    • Linux server (Ubuntu recommended)
    • User account with sudo privileges
    • SSH server enabled
  • SSH (Secure Shell)
    • Protocol for secure remote system administration
    • Key-based authentication
    • OpenSSH implementation
  • IDE Integration
    • VS Code Remote Development Extension Pack
    • Remote SSH capabilities
    • Integrated terminal support
  • Configuration Management
    • SSH config files
    • IDE workspace settings
    • Environment variables
  1. Security
  • Key-based authentication
  • No password storage
  • Encrypted connections
  1. Development Experience
  • Direct remote file editing
  • Integrated terminal access
  • Automatic workspace opening
  • Multiple remote workspace management
  1. Efficiency
  • Single-click connections
  • Persistent sessions
  • Automatic directory navigation
  • Shared SSH configurations
  1. Team Collaboration
  • Standardized setup process
  • Shared development environments
  • Consistent workspace structures
Terminal window
ls -la ~/.ssh

Look for files like id_ed25519, id_rsa, or similar. If none exist, proceed to step 2.

Terminal window
ssh-keygen -t ed25519 -C "your.email@company.com"
# for example "terry@eonlabs.com" is the "your.email@company.com"
  • Press Enter to accept default location
  • Enter a secure passphrase (recommended)
Terminal window
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519 # or your key name
Terminal window
ssh-copy-id -i ~/.ssh/id_ed25519.pub username@remote-server
# tca

Or manually:

Terminal window
cat ~/.ssh/id_ed25519.pub | ssh username@remote-server "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"
Terminal window
nvim ~/.ssh/config

Basic template:

Host remote-nickname*
HostName server.address
User your-username
Port 22
ForwardAgent yes
IdentityFile ~/.ssh/your_private_key
IdentitiesOnly yes
PermitLocalCommand yes
Host remote-nickname-workspace1
RemoteCommand cd /home/username/workspace1
LocalCommand code --remote ssh-remote+remote-nickname-workspace1 /home/username/workspace1
Terminal window
# Test basic connection
ssh remote-nickname
# Test specific workspace connection
ssh remote-nickname-workspace1

On remote server:

Terminal window
ls -la ~/.ssh
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
  • Check SSH agent: ssh-add -l

  • Test verbose connection: ssh -v remote-nickname

  • Check remote logs: tail -f /var/log/auth.log (on remote server)

  • Verify key permissions: chmod 600 ~/.ssh/id_ed25519 Remember to replace:

  • username with actual username

  • remote-server with actual server address

  • remote-nickname with desired SSH host alias

  • Key filenames with actual key names

  • Workspace paths with actual paths