4

I know that the chsh command is used to switch login shell for a user between installed shells, but it works regardless of where login comes from (tty1, tty2, ssh, ...). What I'd like to achieve is to have e.g. csh on logins from tty7 and e.g. bash on all other login sources.

Is this doable at all?

Kusalananda
  • 333,661
Anonymous
  • 195

1 Answers1

10

No and yes.

No, the login shell is tied to the user, not to the TTY where the user logs in. A user can only have one specific login shell.

Yes, the user may, in the login shell's initialization files, start any other program or utility depending on any condition.

For example, a user with bash as their current login shell could add something like the following to their .bash_profile file to run csh when logging in on virtual terminal 7:

case $(tty) in
    */tty7) exec csh -l ;;
esac

exec csh -l would replace the current shell with csh, started as a login shell.

Kusalananda
  • 333,661
  • Sounds reasonable, going to check it out - thx! – Anonymous Feb 08 '18 at 18:03
  • 1
    omg it worked! btw, names are /dev/tty1 ... tty63 so I've changed pattern after 'in' to *tty7. SO MUCH THANK YOU! – Anonymous Feb 08 '18 at 18:11
  • The pseudo-terminals used by SSH and terminal emulators are /dev/pts/0..., the fixed virtual and serial terminals are tty1... and ttyS0... The numbers of the pts/N ones don't really mean anything, they're just allocated so that you get the next free one. – ilkkachu Feb 08 '18 at 18:32
  • @ilkkachu Thanks for the info and for the edit! – Kusalananda Feb 08 '18 at 18:43