Note: You don't need any special options with SSH as the SSH server always creates a login shell to be accessed by the SSH client. It works for localhost as well as for other hosts and provides public key authentication that works without any interactive input. As user2 set your display (assuming default case): DISPLAY:0 export DISPLAY Then run: xauth add DISPLAY. You could have different displays associated with those hosts as well. If you want to run commands as a different user without performing authentication from the keyboard, you might want to use SSH instead. 43 To use xauth selectively, as user1 run: xauth listgrep uname -n This prints the hexkey authorization entries for you. I noticed that you are using -S and I don't think it is generally a good technique. etc/sudoers: smith ALL (jones) /usr/local/bin/mycommand User smith runs: smith sudo -u jones /usr/local/bin/mycommand smith sudo -u jones mycommand If /usr/local/bin is in PATH User smith will be prompted for his own password, not jones’s. # strace -f -e process sudo -S -i -u user echo \$HOMEĮxecve("/usr/bin/sudo",, ) = 0 Solution Suppose you want user smith to be able to run a given command as user jones. The output bellow shows that the shell is being called with -login and with the specified command, just as in your explicit call to bash, but in addition sudo can do its own work like setting the $HOME. I have just checked the last example with strace which tells you exactly what's happening. Note: The backslash character ensures that the dollar sign reaches the target user's shell and is not interpreted in the calling user's shell. When command is not specified you'll get a login shell prompt, otherwise you'll get the output of your command.Įxample (with a specified user): sudo -i -u userĮxample (with a command): sudo -i -u user whoamiĮxample (print user's $HOME): sudo -i -u user echo \$HOME For example, when there is only one user account registered on the system, or when an automated script requires elevated privileges to perform certain tasks.To invoke a login shell using sudo just use -i. In some cases, it may be useful to disable this mechanism. Running sudo su without a passwordīy default, a command run with sudo requires that the user authenticates themselves using their own password. ![]() Note that the sudo -su command differs from sudo su - in the sense that the su expression will be treated as option flags of the sudo command, where the -s flag is used to run a new shell, and the -u flag is used to run a command as a user different from root. Change the current directory to the user’s home directory.ĭon’t confuse sudo -su with sudo su -!. ![]() If you run sudo -s that will start a shell as root. set inactive 30 Jun 23:43:44 - info Settings file : /Users/nol/.node-red/settings.js 30. Another way to switch to another account with sudo is to use the -s option. ![]()
0 Comments
Leave a Reply. |