596 words
3 minutes
Passwordless Remote Login

I. SSH Passwordless Login — Key-Based Authentication#

Overview: The goal is to log in to a remote server (e.g., spiedie.binghamton.edu) from Mac/Windows/Linux without entering a password, and to make VS Code Remote-SSH connections more stable. This is achieved by replacing password-based authentication with public/private key authentication (公钥/私钥认证).

1. Core Concept: How SSH Passwordless Login Works#

SSH “passwordless login” does not skip identity verification — it replaces password-based authentication with key-based authentication.

1) Two Key Files#

  • Private Key (私钥): stored on your local machine Example: ~/.ssh/id_ed25519 Must never be leaked or shared

  • Public Key (公钥): can be sent to the server Example: ~/.ssh/id_ed25519.pub Safe to share openly / copy to servers

2) How Does the Server Remember You?#

The server stores your public key in:

Terminal window
~/.ssh/authorized_keys

Once added, the server will allow anyone who holds the corresponding private key to log in.

3) What Happens During Authentication (Simplified Flow)#

  1. You initiate a connection: ssh user@host
  2. The server looks up your public key in authorized_keys
  3. The server sends a random challenge
  4. Your machine signs the challenge using your private key (the private key never leaves your machine)
  5. The server verifies the signature using your public key
  6. Verification passes → Login succeeds (no password prompt)

2. Step-by-Step Setup#

The following examples use:

  • Username: xli49
  • Host: spiedie.binghamton.edu

1) Step 1: Generate an SSH Key on Your Local Machine#

Check whether a key already exists:

Terminal window
ls ~/.ssh/id_ed25519 ~/.ssh/id_rsa 2>/dev/null

If not, generate one (ed25519 recommended):

Terminal window
ssh-keygen -t ed25519 -C "xli49@spiedie.binghamton.edu"
Note: For a completely password-free experience, press Enter to leave the passphrase empty. For better security, set a passphrase and use it with Keychain / ssh-agent.

2) Step 2: Copy the Public Key to the Server#

✅ Recommended (when ssh-copy-id is available):

Terminal window
ssh-copy-id xli49@spiedie.binghamton.edu

Enter your password once — that’s the last time.

Manual Method (if ssh-copy-id is not available)#

Terminal window
cat ~/.ssh/id_ed25519.pub | ssh xli49@spiedie.binghamton.edu \
"mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys"

3) Step 3: Test the Passwordless Login#

Terminal window
ssh xli49@spiedie.binghamton.edu

✅ If no password prompt appears → setup successful.


Edit the config file:

Terminal window
nano ~/.ssh/config

Recommended configuration (using the full hostname as the Host):

Host spiedie.binghamton.edu
HostName spiedie.binghamton.edu
User xli49
ServerAliveInterval 300
ServerAliveCountMax 120

After saving, connect with just:

Terminal window
ssh spiedie.binghamton.edu

4. When Is IdentityFile Needed?#

1) Usually Not Required#

SSH automatically tries the following keys in order:

  • ~/.ssh/id_ed25519
  • ~/.ssh/id_rsa
  • Any keys already loaded into ssh-agent

If your key is in one of these default locations, you typically do not need to specify IdentityFile.

2) When You Must Specify IdentityFile#

  • You have multiple keys and SSH might pick the wrong one
  • Your key is not in a default path
  • The server requires a specific key

Example:

Host spiedie.binghamton.edu
HostName spiedie.binghamton.edu
User xli49
IdentityFile ~/.ssh/id_ed25519

5. Preventing VS Code Remote-SSH Disconnections (KeepAlive)#

Common causes of disconnection:

  • The school network or firewall clears long-idle connections
  • The remote session is considered idle when there is no output for an extended period

Solution: enable SSH heartbeat packets (KeepAlive):

ServerAliveInterval 30
ServerAliveCountMax 120

What this means:

  • Send a heartbeat packet every 30 seconds
  • Allow up to 120 consecutive non-responses (~1 hour) before disconnecting

6. Troubleshooting#

1) Check Which Key SSH Is Using#

Terminal window
ssh -v xli49@spiedie.binghamton.edu

Look for lines like:

  • Offering public key: ...
  • Authentication succeeded

2) Check the Default Shell on the Server#

Run remotely to rule out misconfiguration:

Terminal window
echo $SHELL
getent passwd xli49 | cut -d: -f7
which zsh

💡 One-line Takeaway
Generate a key with ssh-keygen -t ed25519, copy it to the server once with ssh-copy-id, add ServerAliveInterval 30 to ~/.ssh/config, and you'll never type a password or suffer a dropped VS Code connection again.
Passwordless Remote Login
https://lxy-alexander.github.io/blog/posts/tools/passwordless-remote-login/
Author
Alexander Lee
Published at
2026-01-30
License
CC BY-NC-SA 4.0