SSH Keys to Remote Linux (No Need to type password again!!!)
Source: Notion | Last edited: 2024-11-19 | ID: 1382d2dc-3ef...
Overview
Section titled “Overview”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.
Prerequisites
Section titled “Prerequisites”- 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
Tools & Technologies
Section titled “Tools & Technologies”- 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
Benefits & Enhancements
Section titled “Benefits & Enhancements”- Security
- Key-based authentication
- No password storage
- Encrypted connections
- Development Experience
- Direct remote file editing
- Integrated terminal access
- Automatic workspace opening
- Multiple remote workspace management
- Efficiency
- Single-click connections
- Persistent sessions
- Automatic directory navigation
- Shared SSH configurations
- Team Collaboration
- Standardized setup process
- Shared development environments
- Consistent workspace structures
SSH Setup Tutorial for Remote Development
Section titled “SSH Setup Tutorial for Remote Development”1. Check Existing SSH Keys
Section titled “1. Check Existing SSH Keys”ls -la ~/.sshLook for files like id_ed25519, id_rsa, or similar. If none exist, proceed to step 2.
2. Generate SSH Key
Section titled “2. Generate SSH Key”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)
3. Start SSH Agent
Section titled “3. Start SSH Agent”eval "$(ssh-agent -s)"ssh-add ~/.ssh/id_ed25519 # or your key name4. Copy Key to Remote Server
Section titled “4. Copy Key to Remote Server”ssh-copy-id -i ~/.ssh/id_ed25519.pub username@remote-server# tcaOr manually:
cat ~/.ssh/id_ed25519.pub | ssh username@remote-server "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"5. Create SSH Config
Section titled “5. Create SSH Config”nvim ~/.ssh/configBasic 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/workspace16. Test Connection
Section titled “6. Test Connection”# Test basic connectionssh remote-nickname
# Test specific workspace connectionssh remote-nickname-workspace17. Verify Remote Permissions
Section titled “7. Verify Remote Permissions”On remote server:
ls -la ~/.sshchmod 700 ~/.sshchmod 600 ~/.ssh/authorized_keys8. Troubleshooting
Section titled “8. Troubleshooting”-
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_ed25519Remember to replace: -
usernamewith actual username -
remote-serverwith actual server address -
remote-nicknamewith desired SSH host alias -
Key filenames with actual key names
-
Workspace paths with actual paths