Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I do sudo <command> and enter the password, my Debian Squeeze remembers the fact I passed the password and never asks for it for i.e. 15 minutes.

But if I do sudo -i and then exit, the system does not remembers the password and asks for it all over again every time I use sudo -i. Doing just once sudo <command> makes the system not ask for password even for a next sudo -i.

Here are the scenarios I've described above:

First one:

  1. login (by SSH),
  2. sudo <command>: system's asking for the password,
  3. sudo -i: system is not asking for the password.

Second one:

  1. login (by SSH),
  2. sudo -i: system's asking for the password,
  3. exit
  4. sudo -i: system's again asking for the password.

Doing something beetween 2. and 3. makes the system remember the password.

What is the reason of such a behaviour? Is it possible to make the system remember the password (fact I passed it) also after using sudo -i?

share|improve this question

migrated from serverfault.com Jun 3 '13 at 4:02

This question came from our site for system and network administrators.

If I do sudo -i, immediately exit or logout and then again sudo -i, the password is properly remembered and the second sudo command doesn't ask for it. – Pavel Šimerda Apr 16 '14 at 21:36
up vote 0 down vote accepted

From the sudoers(5) man page:

As a special case, if sudo's -i option (initial login) is specified, sudoers will initialize the environment regardless of the value of env_reset. The DISPLAY, PATH and TERM variables remain unchanged; HOME, MAIL, SHELL, USER, and LOGNAME are set based on the target user. On Linux and AIX systems the contents of /etc/environment are also included. All other environment variables are removed

The fact that USER is being set, would likely mean that regardless of your passwd success, that counter is getting reset.

There are other knowledge points in that documentation you should be aware of as well.

share|improve this answer
And what about the fact "Doing sth beetween 2. and 3. makes the system remember the password."? Doing sth changes the 'counter'? – jacek.ciach Jun 4 '13 at 17:13
I am sorry, I don't know what 'sth' means. But if it means 'steps' then then why does it not ask for the password between the steps? Because step 2 you are not using the -i and so it remembers the password, in the third step, then the rules apply according to the documentation. Once the exit is done, you are changing environments by changing the shell. – vgoff Jun 7 '13 at 5:43
sth = something – jacek.ciach Jun 7 '13 at 10:04
Doesn't seem to answer the question at all, even though accepted. – Pavel Šimerda Apr 16 '14 at 21:35
Doesn't answer which question? There were two. – vgoff Apr 18 '14 at 16:12

Your Answer


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.