How to get the shell you want

jdavidb on 2006-11-21T20:31:22

Despite my best efforts, most people around here still don't know that they prefer bash. Which is odd, since this is where I learned to prefer bash.

I have my Cygwin .Xinitrc menus and ssh keys set up to give me instant right-click-and-select-a-host access to just about everything I need. Except that for most of the servers I've added recently, that takes me somewhere where the shell is not bash, and where I'm not the account owner and/or don't have what I need to get bash set up as the default shell.

For awhile I've been considering putting something in the login files to examine the SSH_CLIENT variable and exec bash when the IP address looks like mine. But that sounds a little fragile and therefore scary: what if somebody else using one of these accounts gets my bash config and doesn't want it? What if it breaks completely, when someone else is accessing the account, and they can't even get a regular shell and have no idea what happened?

I'd previous tried ssh user@host bash, but that didn't seem to work. For some reason, it seemed to take forever, even though executing other arbitrary commands through ssh worked just fine.

So today I tried it again, and then I typed something and hit enter while ssh was "taking forever." And I discovered ssh wasn't taking forever -- it had logged in and started a bash for me, which was executing in batch mode or something, with no prompt. I got the same result trying to run other shells, actually.

So I dug through the ssh manpage and found out that if I pass the -t option, ssh will allocate a tty for the connection, which causes bash to realize it is supposed to be running interactively, and everything works fine! .XWinrc updated!

While writing this entry, I decided to check to see if there were an option I could pass to bash to just tell it to be an interactive shell. I had previously tried bash --login, and that didn't work. Turns out you can specify an interactive shell with the -i option, but that won't do you a lot of good if you aren't using a tty, because the input and output will be in raw mode instead of cooked. You'll get a lot of junk echoed.

Now I just need to figure out why I can't sudo - user bash on some hosts.