[Solved]Can anyone tell me why -H flag with sudo doesn't switch to the target user's home directory? | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

[Solved]Can anyone tell me why -H flag with sudo doesn't switch to the target user's home directory?

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-05-2013
Michaelw321 Michaelw321 is offline
Registered User
 
Join Date: Aug 2012
Last Activity: 18 February 2013, 4:01 AM EST
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
[Solved]Can anyone tell me why -H flag with sudo doesn't switch to the target user's home directory?

I have checked the man page ,which says :

The -H (HOME) option sets the HOME environment variable to the homedir of
the target user (root by default) as specified in passwd(5). By default,
sudo does not modify HOME

But I have tried below command:

Code:
[root@shel0001 ~]# sudo -H -s -u wanglei
[wanglei@shel0001 /root]$ pwd
/root

as you can see ,it still stays in the /root and doesn't change to user wanglei's home directory which is /home/wanglei, what am I missing ,please help me
Sponsored Links
    #2  
Old 02-05-2013
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
 
Join Date: Sep 2005
Last Activity: 27 July 2014, 5:28 AM EDT
Location: Switzerland - GE
Posts: 5,609
Thanks: 151
Thanked 387 Times in 364 Posts
It says "sets the HOME..." not goes to...
Look:

Code:
ran12:/home/vbe/admin/script $ sudo -H -u prod -s
ran12:/home/vbe/admin/script $ id
uid=1101(prod) gid=220(prod) groups=60(oper),300(dba),310(sas)
ran12:/home/vbe/admin/script $ cd
ran12:/prd/users/prod $

And so, it was set correctly as specified in the man pages...
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
[Solved] Unable to change/create home dir for particular user fretagi HP-UX 8 09-19-2012 09:16 AM
sudo needs to source target user's .shrc mp5802 UNIX for Advanced & Expert Users 2 08-11-2011 01:46 PM
How to switch user in shell scripting (without sudo)? edgarvm Shell Programming and Scripting 8 01-08-2010 01:24 PM
Restricting SFTP user to a defined directory and home directory sftpuser Solaris 1 10-16-2009 07:00 PM
Problem: Automounting Home directory for nis & nfs configuration doesn't work pioneer UNIX for Advanced & Expert Users 0 10-18-2007 02:07 PM



All times are GMT -4. The time now is 05:26 AM.