Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have multiple servers that I need to remote into. I prefer Cygwin over Putty to do so.

Anyhows - the process of opening my cool Mintty window and then typing the following commands takes too long. PS - I am using a "key" authentication to these servers.

First, I double Click Cygwin Terminal shortcut from my windows desktop.

Then once the terminal session has booted up, from the command prompt I type the following -

$ eval `ssh-agent`
$ ssh-add
$ ssh <username>@<servername>

Please keep in mind that my 'servername' is variable. In fact I have about 10 different server names that could potentially be inserted there - Hence my need for 10 different shortcuts. I would prefer to double click on something from my desktop that will fire up my Mintty and automatically execute the above bash shell commands.

Does anyone have or can recommend a nice/elegant solution to do this?

share|improve this question
up vote 4 down vote accepted

You need to create a shell script and then have a mintty shortcut that calls it. First, the script:

#!/bin/bash

eval `ssh-agent`
ssh-add
read -p "Username: "
username=$REPLY
read -p "Host: "
host=$REPLY
ssh $username@$host
eval `ssh-agent -k`

Save this as something like: ~/bin/CygwinMinttySsh.sh

Make sure the script is executable: chmod a+rx ~/bin/CygwinMinttySsh.sh

Then create a new shortcut to C:\cygwin\bin\mintty.exe, then right-click on it and select "properties" and change the target to:

C:\cygwin\bin\mintty.exe -e /bin/sh -l -c '$HOME/bin/CygwinMinttySsh.sh'
share|improve this answer
    
I tried this - but when I double click on the shortcut icon - the mintty window appears for a split second and then goes away. – Alex Berkoff Aug 30 '12 at 23:50
    
Make sure your path to your script is correct. Also, make sure the script itself is set to be executable (chmod a+rx ~/bin/CygwinMinttySsh.sh) and that it runs correctly from an existing shell (so you can see error messages). – Heptite Aug 30 '12 at 23:52
    
Excellent work Heptite. Have a brew on me and send me the bill. Cheers! – Alex Berkoff Aug 31 '12 at 0:05
    
I just realized that you probably want to kill the ssh-agent at the end of the script. My answer has been modified. – Heptite Sep 7 '12 at 21:03

There are actually a couple of ways for you to do this. If you really need to run the commands you have listed before performing the ssh, then place these commands into a file called myssh in your cygwin home directory.

eval `ssh-agent`
ssh-add
ssh <username>@$1

Obviously put the username that you want to use where you have <username>.

You can then run this by using the following command:

c:\cygwin\bin\bash --login myssh <servername>

You can of course put that into a BAT file.

share|improve this answer
    
I looked at your approach and it too would work, but it's not as clean as the approach above. Thank you for your reply though. – Alex Berkoff Aug 31 '12 at 0:08
    
Yes, I +1'ed @Heptite's solution ... – HeatfanJohn Aug 31 '12 at 0:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .