

Where obviously you need to create otheraccount and make sure it has the privileges that are required for performing this particular task. Ideally, you might want to make sure that my_prog runs on a dedicated unprivileged system account then, the syntax would be su otheraccount -c /path/my_prog Running a shell makes sense when you actually require shell features such as wildcard expansion, redirection, etc, or shell builtins like cd. Sh -c "command" is just an inefficient way to run command.
#SU SUDO PASSWORD#
Sudo makes sense if you are running on an unprivileged account, and have been granted the rights to switch to another account (often, but not always, root), usually with the requirement to be able to interactively supply your password (though this can be turned off if you really have to obviously, you need to understand what you are doing before you mess with security-related stuff). Su makes sense if you are root and want to switch to a different account. The correct answer is to simply run your command. Then your script can be readable, but your password file can't be.You don't need any of them rc.local runs with root privileges. More indirectly, you can store your password in a file and cat it to sudo.

Make sure the script is only readable by yourself, as your password is in it. Running Program As Another User / sudo Command The sudo command allows a user to start programs with the credentials of another user. These options are documented under man sudo. Look at the above snapshot, command 'su -' has assumed root as the target. The -u user option means to run the command as the specified user rather than root. The -s option means to run the shell specified in the environment variable SHELL if this has been set, or else the user's login shell.
#SU SUDO HOW TO#
Your next question is probably how to pass a password in an unattended script, which doesn't require user input. (here root password is assumed to have been configured because user is familiar with ‘su’. Where command is the command for which you want to use sudo. While su shows: +───bash───sudo───su───bash If user only uses ‘su’ command and want to use ‘su’ as ‘sudo’ then it can be done. sudo su shows (assuming bash): +───bash───su───bash sudo sudo, which is an acronym for superuser do or substitute user do, is a command that runs an elevated prompt without a need to change your identity. You can see the difference if you look at the process tree. This isn't a security issue, as the shell process can't escalate to the privileges of the parent process. Have you ever tried to edit a config file only to receive 'Permission Denied' (The /etc/hosts file comes to mind.) If so, that was because your user account did not have access to that file. In terms of privileges, there is no difference for the shell that is opened by sudo su or by su. Sudo stands for 'superuser do' and is the master key to your high-privilege admin tasks. After that it will start a shell for user someuser. For example, if you enter the command su bob, you will be prompted for Bobs password. It will however ask for your password to verify your sudo rights. The su command in Linux is used to switch to a different user account. So it doesn't ask for someuser's password.

su (without username) start a shell for user root (after asking for the root password).Unless you're root, you'll be asked the password for someuser.
