Weblog entry #20 for lters

sudo in squeeze
Posted by lters on Wed 19 Jan 2011 at 10:52
Tags: none.
On some of our boxes we are running squeeze.
And I find that sudo -s changes the current user to root.
The breaks all the current users aliases and environment.
Normally after logging into a box, and needed to do root type things, sudo -s gets me privileges but keeps everything like my pwd, aliases, environment vars etc.

Is there anyway to get the current /Lenny/ behavior back?
That was much nicer or was I doing something I should not have been doing?

 

Comments on this Entry

Posted by Anonymous (173.75.xx.xx) on Wed 19 Jan 2011 at 12:58
See bug #49587.

[ Parent | Reply to this comment ]

Posted by lters (12.162.xx.xx) on Wed 19 Jan 2011 at 13:03
[ View lters's Scratchpad | View Weblogs ]
Where is that bug listed?
Debian bug 49587 does not look like its related.

lters

[ Parent | Reply to this comment ]

Posted by Anonymous (87.182.xx.xx) on Wed 19 Jan 2011 at 13:04
try sudo -H -i

Peter

[ Parent | Reply to this comment ]

Posted by lters (12.162.xx.xx) on Wed 19 Jan 2011 at 13:07
[ View lters's Scratchpad | View Weblogs ]
Thanks...
But that is not what sudo -s does in lenny though...

I want to keep the same userid/profile etc and just have root access like sarge,etch,lenny etc work.

regards, lters

[ Parent | Reply to this comment ]

Posted by Anonymous (208.106.xx.xx) on Wed 19 Jan 2011 at 15:26
yes, sudo's behavior changed in squeeze. from /usr/share/doc/sudo/NEWS.Debian.gz:
sudo (1.7.4p4-2) unstable; urgency=low

The HOME and MAIL environment variables are now reset based on the
target user's password database entry when the env_reset sudoers option
is enabled (which is the case in the default configuration). Users
wishing to preserve the original values should use a sudoers entry like:
Defaults env_keep += HOME
to preserve the old value of HOME and
Defaults env_keep += MAIL
to preserve the old value of MAIL.

The change in handling of HOME is known to affect programs like pbuilder.

-- Bdale Garbee <bdale@gag.com> Wed, 08 Sep 2010 14:29:16 -0600

[ Parent | Reply to this comment ]

Posted by lters (12.162.xx.xx) on Wed 19 Jan 2011 at 18:42
[ View lters's Scratchpad | View Weblogs ]
This fixed it, thanks so much.

regards, lters

[ Parent | Reply to this comment ]

Posted by rjc (131.111.xx.xx) on Wed 19 Jan 2011 at 14:21
Look at the /etc/sudoers line:

Defaults env_reset

man sudoers

rjc

[ Parent | Reply to this comment ]

Posted by lters (12.162.xx.xx) on Wed 19 Jan 2011 at 15:13
[ View lters's Scratchpad | View Weblogs ]
With it on or off, neither way seems to make it work in squeeze like it does in lenny.

Something is broken or different with squeeze sudo it seems.
Or what am I missing.

regards, lters

[ Parent | Reply to this comment ]

Posted by mcortese (20.142.xx.xx) on Wed 19 Jan 2011 at 17:37
[ View Weblogs ]
Can you be more explicit in detailing what is that you do, what you expect and what you get?

I use squeeze and AFAIK sudo does preserve my working dir. Aliases, however are not preserved when you run a new instance of bash, with or without switching user, so there's nothing sudo can do about it...

[ Parent | Reply to this comment ]

Posted by lters (12.162.xx.xx) on Wed 19 Jan 2011 at 17:52
[ View lters's Scratchpad | View Weblogs ]
ssh <machine>
~.bash_profile setups lots of shortcut aliases.

sudo -s then would take me from $ to #,
give me root access,
and all aliases would follow me.

As soon as I update a box to squeeze, the aliases break. IE I can redefine them, but there are not there anymore.

Is there a way to make the sudo environment rerun the ~.bash_policy file to setup the aliases again?

regards, lters

[ Parent | Reply to this comment ]

Posted by mcortese (20.142.xx.xx) on Thu 20 Jan 2011 at 10:07
[ View Weblogs ]
Aliases do not follow you across different bash instances. What you experienced, probably, was that $HOME/.bashrc was re-run in the new bash (as root). When the handling of $HOME changed between lenny and squeeze, that resulted in your $HOME/.bashrc not being run any more. Fix $HOME handling, as others have suggested, and you're done!

However, keep in mind that if you manually assign aliases other than those in your $HOME/.bashrc, they will not follow you anywhere. Functions, on the other hand, can be made to follow you with the export -f built-in command.

[ Parent | Reply to this comment ]

Posted by lters (12.162.xx.xx) on Thu 20 Jan 2011 at 10:29
[ View lters's Scratchpad | View Weblogs ]
That makes sense and is very helpful.

Perhaps making functions would be just as good or better than making aliases.
Fixing the $HOME fix the problem for me and makes it work in squeeze just like it did in lenny.

Hopefully if anyone else has this issue they can follow this thread to get their issue fixed as well.

Just to recap:
If sudo -s is missing your bash profile setup in squeeze, you will need to run visudo and add this line: "Defaults env_keep += HOME" to fix it.


regards, lters

[ Parent | Reply to this comment ]

Posted by dalitec (108.170.xx.xx) on Sat 22 Dec 2012 at 12:59
[ View Weblogs ]
I am having sudo squeeze issue also. I am new here and apologize if I am adding this comment here about a sudo problem in squeeze. I thought I would ask here. but also posted a separate weblog under my account. My sudo problem is sudoing as another user using -U but still asked for my password and not the other user password. Thanks and again apologize for posting my issue here.

[ Parent | Reply to this comment ]