ssh / cygwin / windows quick & dirty



This guide is for the people who only want to get this thing done where you only type ```bash ssh remotehost ``` to ssh to your server at `crazylongdomainname.com` with the user `u3321445longandunhandy` on a windows pc with cygwin. <span id="more-1974"></span> ## Configure this domain shortcuts Edit the file `~/.ssh/config` such that it contains ```bash Host remotehost Hostname crazylongdomainname.com User u3321445longandunhandy ``` ## openssh Install openssh using cygwin setup.exe. ## Create a Keypair Open `mintty` and type ```bash 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. ```bash scp yourcomputername-key.pub remotehost:/home/u3321445longandunhandy/ ``` Then ssh to the remote host and create a script called `create-ssh-dir`: ```bash 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 ```bash 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: ```bash 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`.

Tags: -

Leave a Reply

Your email address will not be published. Required fields are marked *