Sponsored Content
Top Forums UNIX for Dummies Questions & Answers [Solved]Can anyone tell me why -H flag with sudo doesn't switch to the target user's home directory? Post 302766581 by Michaelw321 on Tuesday 5th of February 2013 04:27:35 AM
Old 02-05-2013
[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
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Problem: Automounting Home directory for nis & nfs configuration doesn't work

Hi all, First of all, i am so sorry about my bad level in English writing. I have some problem in linux and i hope the experts of this forum to help me if they have enough time to reply to me. I have a scenario of configuring NIS and NFS in Redhat Linux environment such that user can login... (0 Replies)
Discussion started by: pioneer
0 Replies

2. Solaris

Restricting SFTP user to a defined directory and home directory

Hi, I've created solaris user which has both FTP and SFTP Access. Using the "ftpaccess" configuration file options "guest-root" and "restricted-uid", i can restrict the user to a specific directory. But I'm unable to restrict the user when the user is logged in using SFTP. The aim is to... (1 Reply)
Discussion started by: sftpuser
1 Replies

3. Shell Programming and Scripting

How to switch user in shell scripting (without sudo)?

Hi everyone: I have a big trouble, I need create a script that must switch user and then must execute certain commands, sadly neither my user nor the second user have no privileges for sudo, I've tried everything but seems su doesn't accept input redirection, please help me, it's very... (8 Replies)
Discussion started by: edgarvm
8 Replies

4. Red Hat

User's home directory

Hi, By default user's home directory will be /home/$user. I want to change it to /javauser/$user. How can I do it? Thanks Jeevan. (5 Replies)
Discussion started by: jredx
5 Replies

5. Shell Programming and Scripting

How to Toggle Flag/Switch Value with Sed

I am trying to figure out a one liner to toggle a flag variable. eg. FLAG=0 Is there a way to use sed to toggle above example between 0 and 1. That is if run with flag set to zero it would change it to one if run again it would set it to zero. I thought I had it figured but the... (6 Replies)
Discussion started by: bsquared
6 Replies

6. UNIX for Advanced & Expert Users

sudo needs to source target user's .shrc

I'm configuring a sudo Runas_Alias in the sudoers file on a hp-ux 11.31 system. The goal is to allow some hp-ux accounts to sudo to a service account and run commands as that user. Here's the related sudoers entries: User_Alias DMSTAFF = %dmstaff Runas_Alias DMALIAS = dmadmin DMSTAFF ... (2 Replies)
Discussion started by: mp5802
2 Replies

7. Solaris

User directory doesn't exist

Hii all, i create the user useradd -d /home/kk kk passwd kk when i tried to login to kk i get a error user directory doesn't exist then i tried useradd kkk passwd kkkwhen i tried to login to kkk i get the same error user directory doesn't exist. (4 Replies)
Discussion started by: vipinkumarr89
4 Replies

8. HP-UX

[Solved] Unable to change/create home dir for particular user

Hi all I wanted to change the home dir for a user, but when using smh : SMH->Accounts for Users and Groups->Local Users->Modify User ---------------------------------------------------------------------------------------------------------------------------------------------- * Required... (8 Replies)
Discussion started by: fretagi
8 Replies

9. Shell Programming and Scripting

Trying to delete a user and home directory

Good Afternoon, I'm trying userdel -r username on Solaris 9 and getting UX: userdel: ERROR: unable to find status about home directory: No such file or directory I see the user's home directory and getent passwd shows the user Anybody know what's causing it? (2 Replies)
Discussion started by: Stellaman1977
2 Replies

10. Solaris

SunOS confusing root directory and user home directory

Hello, I've just started using a Solaris machine with SunOS 5.10. After the machine is turned on, I open a Console window and at the prompt, if I execute a pwd command, it tells me I'm at my home directory (someone configured "myuser" as default user after init). ... (2 Replies)
Discussion started by: egyassun
2 Replies
RUNUSER(1)							   User Commands							RUNUSER(1)

NAME
runuser - run a command with substitute user and group ID SYNOPSIS
runuser [options] -u user [[--] command [argument...]] runuser [options] [-] [user [argument...]] DESCRIPTION
runuser allows to run commands with a substitute user and group ID. If the option -u is not given, it falls back to su-compatible seman- tics and a shell is executed. The difference between the commands runuser and su is that runuser does not ask for a password (because it may be executed by the root user only) and it uses a different PAM configuration. The command runuser does not have to be installed with set-user-ID permissions. If the PAM session is not required then recommended solution is to use setpriv(1) command. When called without arguments, runuser defaults to running an interactive shell as root. For backward compatibility, runuser defaults to not change the current directory and to only set the environment variables HOME and SHELL (plus USER and LOGNAME if the target user is not root). This version of runuser uses PAM for session management. OPTIONS
-c, --command=command Pass command to the shell with the -c option. -f, --fast Pass -f to the shell, which may or may not be useful depending on the shell. -g, --group=group The primary group to be used. This option is allowed for the root user only. -G, --supp-group=group Specify a supplemental group. This option is available to the root user only. The first specified supplementary group is also used as a primary group if the option --group is unspecified. -, -l, --login Start the shell as a login shell with an environment similar to a real login: o clears all the environment variables except for TERM o initializes the environment variables HOME, SHELL, USER, LOGNAME, PATH o changes to the target user's home directory o sets argv[0] of the shell to '-' in order to make the shell a login shell -m, -p, --preserve-environment Preserve the entire environment, i.e. it does not set HOME, SHELL, USER nor LOGNAME. The option is ignored if the option --login is specified. -s, --shell=shell Run the specified shell instead of the default. The shell to run is selected according to the following rules, in order: o the shell specified with --shell o the shell specified in the environment variable SHELL if the --preserve-environment option is used o the shell listed in the passwd entry of the target user o /bin/sh If the target user has a restricted shell (i.e. not listed in /etc/shells) the --shell option and the SHELL environment variables are ignored unless the calling user is root. --session-command=command Same as -c , but do not create a new session. (Discouraged.) -V, --version Display version information and exit. -h, --help Display help text and exit. CONFIG FILES
runuser reads the /etc/default/runuser and /etc/login.defs configuration files. The following configuration items are relevant for runuser: ENV_PATH (string) Defines the PATH environment variable for a regular user. The default value is /usr/local/bin:/bin:/usr/bin. ENV_ROOTPATH (string) ENV_SUPATH (string) Defines the PATH environment variable for root. The default value is /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin. ALWAYS_SET_PATH (boolean) If set to yes and --login and --preserve-environment were not specified runuser initializes PATH. EXIT STATUS
runuser normally returns the exit status of the command it executed. If the command was killed by a signal, runuser returns the number of the signal plus 128. Exit status generated by runuser itself: 1 Generic error before executing the requested command 126 The requested command could not be executed 127 The requested command was not found FILES
/etc/pam.d/runuser default PAM configuration file /etc/pam.d/runuser-l PAM configuration file if --login is specified /etc/default/runuser runuser specific logindef config file /etc/login.defs global logindef config file SEE ALSO
setpriv(1), su(1), login.defs(5), shells(5), pam(8) HISTORY
This runuser command was derived from coreutils' su, which was based on an implementation by David MacKenzie, and the Fedora runuser com- mand by Dan Walsh. AVAILABILITY
The runuser command is part of the util-linux package and is available from Linux Kernel Archive <https://www.kernel.org/pub/linux/utils /util-linux/>. util-linux July 2014 RUNUSER(1)
All times are GMT -4. The time now is 03:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy