Skip to content

Instantly share code, notes, and snippets.

@richxcame
Last active December 29, 2021 18:57
Show Gist options
  • Save richxcame/91dcfd66cc30a4a30b56abf52a8c2129 to your computer and use it in GitHub Desktop.
Save richxcame/91dcfd66cc30a4a30b56abf52a8c2129 to your computer and use it in GitHub Desktop.
Connect with ssh without typing password

How to ssh to a remote server without typing your password

# The hostname of your remote server.
[email protected]

# Create this folder if it does not exist: ~/.ssh
mkdir ~/.ssh

# Set the correct permissions (required)
chmod 700 ~/.ssh

# Generate an RSA key pair for identification with the remote server
ssh-keygen -t rsa

# Copy your public key to the remote server
cat ~/.ssh/id_rsa.pub | ssh $host 'cat >> ~/.ssh/authorized_keys'

# ssh is very strict about correct permissions
ssh $host 'chmod g-w,o-w ~; chmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized_keys'

At this point you can without typing your code:

You can also alias hostname of your remote server with creatig file ~/.ssh/config

# ~/.ssh/config

Host rich
    User username
    Hostname example.com

At this point you have simple shorthand, if you type this you are in remote server.

ssh rich
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment