Start SSH in ConEmu

How can I set a shortcut in ConEmu to automatically open a new tab with Cygwin, and automatically start a given command (Say, SSH)?


Solution 1:

So lets start with how to launch cygwin bash in a new tab. In my example I am using msys-git's cygwin bash because that's what I have installed:

Git Bash Task

The command I use is:

%systemroot%\SysWOW64\cmd.exe /c ""C:\Program Files (x86)\Git\bin\sh.exe" --login -i"

So that's an interactive shell. If I want to run ls from inside of cygwin bash, I can use sh -exec instead of sh --login -i It would look like this:

C:\Users\JDearing>"C:\Program Files (x86)\Git\bin\sh.exe" -exec "/bin/ls c:\\"
+ /bin/ls c:
$Recycle.Bin               VC_RED.MSI     install.exe
BOOTSECT.BAK               VC_RED.cab     install.ini
Chocolatey                 Windows        install.res.1028.dll
Documents and Settings     boot           install.res.1031.dll
EntLib41Src                bootmgr        install.res.1033.dll
Intel                      eula.1028.txt  install.res.1036.dll
MSOCache                   eula.1031.txt  install.res.1040.dll
PerfLogs                   eula.1033.txt  install.res.1041.dll
Program Files              eula.1036.txt  install.res.1042.dll
Program Files (x86)        eula.1040.txt  install.res.2052.dll
ProgramData                eula.1041.txt  install.res.3082.dll
Recovery                   eula.1042.txt  old_machine
RiskWorks                  eula.2052.txt  pagefile.sys
SWSetup                    eula.3082.txt  profiles
SafeBoot.fs                globdata.ini   sysinternals
SafeBoot.rsv               hiberfil.sys   vcredist.bmp
System Volume Information  ilspy
Users                      inetpub

C:\Users\JDearing>

So you can probably start ssh from cygwin bash with something like:

%systemroot%\SysWOW64\cmd.exe /c ""C:\Program Files (x86)\Git\bin\sh.exe" -exec "/usr/bin/ssh [email protected]""

You might have to play with quotes. I'd suggest looking at my conemu tasks for reference.

Solution 2:

This is the most seemless way to get an SSH task up and running through ConEmu. Requires a bit more configuration, but it's worth it in the end.

Generate an ssh-key

Steps from excellent answer here: https://serverfault.com/questions/241588/how-to-automate-ssh-login-with-password. ssh-keygen will ask you a few questions. The default answers are fine. If you want to go with a blank passphrase, that's fine as well. Just keep your keyfile safe. Replace id, server and password with your credentials.

$ ssh-keygen -t rsa -b 2048

$ ssh-copy-id id@server password

$ ssh id@server

Add a task for ssh

  • Open the ConEmu settings, go to Startup->Tasks.
  • Click +
  • Name task something (I used "ssh")
  • In the large textbox for Commands, Tabs, Etc, place a new command:
    • ""C:\Program Files\Cmder\vendor\git-for-windows\bin\sh.exe" -exec "/usr/bin/ssh id@server""
    • Replace id and server with your own

(Optional) Set task as default task

  • Switch to the parent setting window "Startup"
  • In "Startup options" select the "Specified named task" radio button
    • From the dropdown, select the name of your task (ssh in my case)
  • Save settings

If you did everything correctly, your console will start up and ssh into your server of choice, no password required since you're using a passkey.

Solution 3:

C:\cygwin64\bin\bash.exe --login -i -c "ssh myUser@myServer"

the -c will execute the following string command automatically after logging in for you