Start ssh in conemu

8

3

how can I set a shortcut in conEmu to automatically open a new tab with cygwin, and automatically start a given command (say, ssh) ?

Car981

Posted 2013-04-29T17:27:35.967

Reputation: 305

Answers

6

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 Car981@linuxbox.domain.com""

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

Justin Dearing

Posted 2013-04-29T17:27:35.967

Reputation: 2 704

2I had to use bash.exe -c "ssh ..." rather than bash.exe --exec "ssh ..." – Michael – 2016-05-15T23:58:22.990

3cmd /c is excess in fact, unless you need to set up any environment variables before running ssh.exe. If you don't need to set up environment - you may run ssh.exe directly, without "cmd /c". – Maximus – 2013-04-29T19:48:00.197

If I run it directly, it doesn't attach to conemu though. What should I do ? – Car981 – 2013-04-30T06:19:12.197

1

@Car981 You need to add that to a task like this. Also look at -new_console

– Justin Dearing – 2013-04-30T15:52:10.247

3

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.

codepringle

Posted 2013-04-29T17:27:35.967

Reputation: 128

2

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

meffect

Posted 2013-04-29T17:27:35.967

Reputation: 150

The other answers to this question are quite expansive, can you elaborate on this at all? – bertieb – 2017-02-18T23:19:01.943

added some more – meffect – 2017-02-18T23:32:37.563