This guide is for the people who only want to get this thing done where you only type
ssh remotehost
to ssh to your server at crazylongdomainname.com
with the user u3321445longandunhandy
on a windows pc with cygwin.
## Configure this domain shortcuts
Edit the file ~/.ssh/config
such that it contains
Host remotehost
Hostname crazylongdomainname.com
User u3321445longandunhandy
## openssh
Install openssh using cygwin setup.exe.
## Create a Keypair
Open mintty
and type
ssh-keygen -t ecdsa -f yourcomputername-key
You can use a passphrase or not. You will be prompted for this password whenever you want to use your private key. First, this seems as unhandy as entering it everytime you connect to the remote host, but it will turn out to be much more handy. We end up with two files:
yourcomputername-key
: your **private** key, make sure no one gets it.
yourcomputername-key.pub
: your **public** key, make sure everyone gets it.
## Copy public key to server
Copy your public key to the remote host. You can use e.g.
scp yourcomputername-key.pub remotehost:/home/u3321445longandunhandy/
Then ssh to the remote host and create a script called create-ssh-dir
:
if [ ! -d .ssh ]; then mkdir .ssh ; chmod 700 .ssh ; fi
mv $1 .ssh/
cd .ssh/
if [ ! -f authorized_keys ]; then touch authorized_keys ; chmod 600 authorized_keys ; fi
cat $1 >> authorized_keys
Make it execuatble with chmod u+x create-ssh-dir
and, well, execute it with ./create-ssh-dir yourcomputername-key.pub
.
If you get error messages involving \r
you have probably issues with so called "windows line breaks": Since windows is so old school and compatible with typewriters, the default for a line-break is \n\r
and not only \n
, which confuses something inside of cygwin. So make sure to configure your text editor correctly.
You can test if everything works by logging out of the remote host and calling
ssh -i yourcomputername-key remotehost
It should now log you into crazylongdomainname.com
with the user u3321445longandunhandy
(because of the .ssh/config
-file) and not prompt you for a password (because of the keypair).
## Use ssh-agent
To get rid of the -i /path/to/yourcomputername-key
, we can use the ssh-agent. I use the following bat-file to start a local shell that has my private key added to it:
ssh-agent bash -c " ssh-add /cygdrive/d/path/to/yourcomputername-key && exec bash "
In this shell you should be able to do ssh remotehost
.