NSLU2-Linux
view · edit · print · history

HowTo.RunAnotherShellForRootSafely History

Hide minor edits - Show changes to markup

July 21, 2008, at 10:39 PM by Kamilion -- All fixed. Sorry for the multiple edits!
Changed lines 32-33 from:

Attempting to use this .profile on SlugOSLE?-4.8beta didn't seem to work, so I tweaked with it until I got a # prompt... Please note that this is obviously NOT completely correct, I only spent 5 minutes on it.

to:

Attempting to use this .profile on SlugOSLE?-4.8beta didn't seem to work as ssh now identifys itself as user@pts/0 instead of user@ttyp0, so I tweaked with it until I got a proper # prompt... Also added a notice banner that BASH was being used instead of sh.

Added line 39:
        echo NSLU2-SlugOS: Interactive SSH Connection detected. Using BASH over SH.
July 21, 2008, at 10:35 PM by Kamilion -- Forgot the grep -q... ^_^
Changed line 37 from:

if [ "$SHELL" = "/bin/sh" ] && [ -z "$BASH" ] && ps $PPID | sed -n -e"/^ *$PPID.*?/p" | grep "sshd: $USER@pts" ; then

to:

if [ "$SHELL" = "/bin/sh" ] && [ -z "$BASH" ] && ps $PPID | sed -n -e"/^ *$PPID.*?/p" | grep -q "sshd: $USER@pts" ; then

July 21, 2008, at 10:30 PM by Kamilion -- Wouldnt work on 4.8
Changed lines 28-46 from:
    --tlhackque
to:
    --tlhackque

Attempting to use this .profile on SlugOSLE?-4.8beta didn't seem to work, so I tweaked with it until I got a # prompt... Please note that this is obviously NOT completely correct, I only spent 5 minutes on it.

/root/.profile

 
if [ "$SHELL" = "/bin/sh" ] && [ -z "$BASH" ] && ps $PPID | sed -n -e"/^ *$PPID.*?/p" | grep "sshd: $USER@pts" ; then
  if [ -x /bin/bash ]; then
        exec /bin/bash
  fi
fi

Good luck!

    --Kamilion
March 30, 2008, at 03:59 PM by tlhackque -- New topic: howto safely use an alternate shell for root
Added lines 1-28:

You may want to run a different shell when using root interactively under unslung.

The (good) advice here has always been 'don't do that, you can mess up the linksys/optware software'.

Here's a work-around that ONLY changes your shell under ssh. (You wouldn't use telnet except in dire circumstances because it's insecure.) The example here is for bash, but you can easily modify it for other shells. Replace /bin/bash with your favorite shell in the two places where it appears.

While we're on the subject of ssh - don't forget to switch PasswordAuthentication? to 'no' in sshd_config - as soon as you've registered your public keys in $HOME/.ssh/authorized_keys.

/root/.profile

 
# Hackque:
#  If we're running under sshd & not already a bash shell, exec bash
#  This allows root to remain a /bin/sh shell for all linksys scripts & processes.
#  It sends interactive sessions to bash
#  'sh' will get a standard shell if desired
#
if [ "$SHELL" = "/bin/sh" ] && [ -z "$BASH" ] && ps $PPID | sed -n -e"/^ *$PPID.*?/p" | grep -q "sshd: $USER@ttyp" ; then
  if [ -x /bin/bash ]; then
        exec /bin/bash
  fi
fi

enjoy,

    --tlhackque
view · edit · print · history · Last edited by Kamilion.
Based on work by Kamilion.
Originally by tlhackque.
Page last modified on July 21, 2008, at 10:39 PM