sudo ignores -H

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I can't get sudo to change directories to the home dir of the target
user, whether or not I pass the -H option on the command line. Any

Also wanted to try "always_set_home" in /etc/sudoers, but I don't know
where to put it (man page doesn't say).

SUSE 9.3

Re: sudo ignores -H

Quoted text here. Click to load it

    Because that's not what -H does.  It sets the $HOME variable; it
does not change your current directory.  I assume you are running a
shell with sudo, which is why you say "I can't get sudo to change
directories".  If you want it to change to the target user's home
directory, use 'sudo su - targetuser' or 'sudo -i'.  From the man page:

      -i  The -i (simulate initial login) option runs the shell
           specified in the passwd(5) entry of the user that the
           command is being run as.  The command name argument
           given to the shell begins with a - to tell the shell
           to run as a login shell.  sudo attempts to change to
           that user's home directory before running the shell.

Oh to have a lodge in some vast wilderness.  Where rumors of oppression
and deceit, of unsuccessful and successful wars may never reach me
    -- William Cowper

Re: sudo ignores -H

Jeremiah DeWitt Weiner wrote:
Quoted text here. Click to load it

Ah, I understand, thanks!

I wanted to be logged in as "frank" and run a command, say
"martys_script" as user "marty". The command is stored in $HOME/bin/,
where $HOME is marty's. How do I do that?

I tried:
   sudo su - marty martys_script
(even with path), but then I get asked for a password (sudo didn't, but
su did, I think).
Also when I try something like
   sudo -i -u marty ls
I get the reply
  ls: command not found

What am I doing wrong?

Site Timeline