Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I followed a tutorial to install Hudson server. In the tutorial was the following Linux command (hudson is a username in Ubuntu):

sudo -Hiu hudson

What is sudo -Hiu for? What happens after I execute this command?

share|improve this question

migrated from stackoverflow.com May 9 '12 at 11:27

This question came from our site for professional and enthusiast programmers.

2 Answers 2

You can type man sudo in your terminal to view the manual.

Hit k/j to scroll up and down.

Hit q to quit.

share|improve this answer
up vote 3 down vote accepted

The -Hiu flag is a combination of the -H, -i, and -u options. Straight out of "man sudo":

   -H          The -H (HOME) option sets the HOME environment variable to
               the homedir of the target user (root by default) as
               specified in passwd(5).  The default handling of the HOME
               environment variable depends on sudoers(5) settings.  By
               default, sudo will set HOME if env_reset or always_set_home
               are set, or if set_home is set and the -s option is
               specified on the command line.

   -i [command]
               The -i (simulate initial login) option runs the shell
               specified in the passwd(5) entry of the target user as a
               login shell.  This means that login-specific resource files
               such as .profile or .login will be read by the shell.  If a
               command is specified, it is passed to the shell for
               execution.  Otherwise, an interactive shell is executed.
               sudo attempts to change to that user's home directory
               before running the shell.  It also initializes the
               environment, leaving DISPLAY and TERM unchanged, setting
               HOME, MAIL, SHELL, USER, LOGNAME, and PATH, as well as the
               contents of /etc/environment on Linux and AIX systems.  All
               other environment variables are removed.

   -u user     The -u (user) option causes sudo to run the specified
               command as a user other than root.  To specify a uid
               instead of a user name, use #uid.  When running commands as
               a uid, many shells require that the '#' be escaped with a
               backslash ('\').  Note that if the targetpw Defaults option
               is set (see sudoers(5)) it is not possible to run commands
               with a uid not listed in the password database.

So what does all this mean? The first useful option is -u, which causes the command (in this case, the shell) to run as user hudson rather than as user root. The -H option makes the home directory equal to hudon's home directory for the duration of the command, and the -i option says to simulate initial login (e.g. source dotfiles) for user hudson. Taken together, these mean: make the command run under user hudson. Since the command in this case is the shell, this means to open a shell as user hudson, just as if you had logged in as user hudson directly.


As a side note: don't use sudo unless you know which command you're running. If you aren't careful, sudo gives you many more opportunities to mess up your system configuration than you have otherwise. That's not to say that you can't fix it, but taking 5 minutes to read the man pages can save hours of fixing problems later.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.