Save yourself a few keystrokes. Follow the steps below:
-
Run this Bash script on your laptop:
#!/usr/bin/env bash # The hostname of your remote server. host=myserver.com # 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 connect to your server without typing a password:
ssh username@myserver.com
-
If you would prefer to type
jupiter
(7 characters) rather thanusername@myserver.com
(21 characters), create a config file~/.ssh/config
on your laptop, as shown below. You'll be able to use thejupiter
alias with:rsync
,scp
, andssh
.# ~/.ssh/config Host jupiter User carl HostName myserver.com
At this point, you can connect to your server like this:
ssh jupiter
-
If you want a single command to do two steps:
- First, connect to a login server
jupiter
- Next, connect to a work server
saturn
Then configure your
~/.ssh/config
file as follows:# ~/.ssh/config Host jupiter User carl Hostname myserver.com Host saturn User carl ProxyCommand ssh -qX jupiter nc %h %p
At this point, you can connect to
saturn
viajupiter
like this:ssh saturn
- First, connect to a login server
How to write your own config file:
All available configuration options: