New app I want to write...

Matts on 2004-01-23T15:49:05

I call this "mssh" (Matt's ssh).

It should remember that if I type:

mssh 10.2.1.1
I really mean
ssh msergeant@10.2.1.1
. But if I try
mssh 10.2.2.2
it should remember I wanted
ssh msergeant@10.2.2.2
.

See I use different usernames in different places. It should be smart enough to cache the user I use on different hosts. And perhaps ask if it hasn't cached one before.

Should be quite trivial to write.


Shell script?

2shortplanks on 2004-01-23T16:14:30

Sounds like you don't want an application but a nice shell alias that passes your arguments though a perl script and reprocesses them before the shell script passes them to ssh.

That way you won't have to worry about the nightmare of dealing with forking, IO transfer, terminals, and ...the list goes on

ssh config?

lachoy on 2004-01-23T16:30:04

With openssh you can setup ~/.ssh/config to do this for you. For instance, at work I'm 'wintercm' while almost everywhere else I'm 'cwinters'. So in ~/.ssh/config I have:

Host mail.optiron.com
User wintercm

And then I can just do 'ssh mail.optiron.com' and it adds the '-l wintercm' in there for me. You can have as many of these 'Host' declarations as you want.

Re:ssh config?

da on 2004-01-23T16:46:02

This also works with arbitrary hostnames, so if you hate typing 'ssh 10.253.189.42' you can shorten it to 'ssh work' in .ssh/config via:

Host work
User blah
HostName 10.253.189.42

...
This also works with ports, X11Forwards, etc.

There's more info in 'man ssh_config' and <plug>I wrote an article for LJ on it too.</plug>

Re:ssh config?

jmason on 2004-01-23T18:45:50

Perfect!

BTW Matt you used the same username twice AFAICS ;)

Re:ssh config?

lachoy on 2004-01-23T21:52:00

That's a really useful article -- thanks for the pointer!

Re:ssh config?

Dom2 on 2004-01-24T19:01:56

The trouble with shortening hostnames is that you still have to type the whole hostname. It's much easier if you can just complete the whole hostname as a command. So, here's a little snippet from my .zshrc (although there's nothing specific to zsh in it, and it should work fine in bash).
if [ -f ~/.ssh/known_hosts ] ; then
    while read host junk
    do
        host=${host%%,*}
        alias "${host}=ssh ${host}"
    done < ~/.ssh/known_hosts
fi

After putting this in place, all you have to do is ssh to a box once and then start a new shell. You then get completion of the hostname as a command to ssh to that hostname. Dead handy!

-Dom