Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 mylogin@myserver.com
  3. After login:

    root@myserver.com:~$

  4. But, press cntrl+D for exit

    root@myserver.com:~$ exit

    root@myserver.com:~$ exit

    ...

    root@myserver.com:~$

    5.Do not quit.

Why?

Please, tell me the correct method.

share|improve this question

migrated from stackoverflow.com May 21 '11 at 22:44

This question came from our site for professional and enthusiast programmers.

add comment

2 Answers 2

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.

share|improve this answer
add comment

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.

share|improve this answer
    
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. –  Seth Robertson May 22 '11 at 3:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.