2

My Step By Step:

  1. On myserver.com i paste line "sudo -s" to file "~/.bashrc" in home directory for "mylogin"
  2. SSH Login to [email protected]
  3. After login:

    [email protected]:~$

  4. But, press cntrl+D for exit

    [email protected]:~$ exit

    [email protected]:~$ exit

    ...

    [email protected]:~$

    5.Do not quit.

Why?

Please, tell me the correct method.

2 Answers 2

5

You can store a flag in an environment variable:

if [ -z $INITIAL_SUDO ]; then
    exec sudo -s INITIAL_SUDO=1
fi

In this case, initial shell invoked by ssh won't have the INITIAL_SUDO flag on and it will spawn sudo process. Shell invoked by sudo, on the other hand, will have INITIAL_SUDO variable set and won't try to call sudo again.

Note that I call exec sudo -s instead of sudo -s. Otherwise, you'll have to press ctrl+D twice: first for a root shell and second for an initial shell which invoked sudo in the first place.

1
  • Also note that if sudo -s breaks for any reason, you are locked out of the machine—at least in interactive mode. If you remember what is going on you can do a non-interactive ssh in to fix things. May 22, 2011 at 3:25
4

The command sudo -s runs a new shell, which executes your .bashrc.

So what happened here, is that you created a loop where each new shell runs sudo -s, which in turn creates a new shell. At some point, the loop reached the RLIMIT_NPROC limit for the system, and the loop stopped, leaving a huge stack of nested shells. This limit is too high on most system (8192 or unlimited) for you to exit them using your keyboard.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .