If necessary, remove the # character at the beginning of the line: # Defaults targetpw # ask for the password of the target user i.e. Make sure that the commenting has been removed in the following lines. Open the /etc/sudoers file using the vim editor. Localhost:~ # sudo zypper install system-user-mail Localhost:~ # sudo zypper install system-group-wheel example execl: couldn't exec /bin/sh execl: Permission denied. The above command is correct, but on Red Hat if selinux is enforcing it will not allow cron to execute scripts as another user. To install the packages, enter the following commands: su -c 'Your command right here' -s /bin/sh username. Locate the system-group-wheel and system-user-mail packages. To assign sudo privileges to a user in Suse Linux, do the following: roaima at 15:28 Ugh, I wish people wouldnt give us the security lecture when its irrelevant to my use case. To check if the change was successful, enter the following command : It asks for the password for current user overexchange at 15:05 Of course it does. To add the user to this group, enter the following ~]# usermod -aG sudo ~]# usermod -aG sudo jsmith To assign sudo privileges to a user in Debian and Ubuntu, you must add the user to the sudo group. To check if the change was successful, enter the following command: To add the user to this group, enter the following ~]# usermod -aG wheel ~]# usermod -aG wheel jsmith su options - running command as another user Ask Question Asked 12 years, 10 months ago Modified 4 years ago Viewed 356k times 111 I was wondering how to run a command as another user from a script. To assign sudo privileges to a user in CentOS 7, CentOS Stream 8, and CentOS Stream 9, you must add the user to the wheel group. To set the password of the new user, enter the following command: To create a new user, enter the following command: To skip entering this information, press Enter.Ĭhanging the user information for maxmustermannĮnter the new value, or press ENTER for the default But launching a program or script owned by another user isn’t the same as running that process as that other user. Ironically, you need root privileges to do so. Optional: Enter additional user information. The sudo -u entry allows allows you to execute a command as if you were another user, but first you have to be granted this privilege in the sudoers file. With sudo, you can run commands as any other user, not just as root. This user has all the rights to administer the operating system. If a non-sudo user tries to use the sudo command, it is logged as a security event. The user can run commands with elevated privileges for a short time (default 15 minutes). Ubuntu 18.04, Ubuntu 20.04, Ubuntu 22.04, Debian 10, and Debian 11 By default, the root user is set up during the installation of Linux. Syntax To start using sudo, use the following syntax: sudo command When the sudo command is used, a timestamp is entered in the system logs. To set the password of the new user, enter the following ~]# passwd ~]# passwd johnsmithĮnter the desired password and repeat it. To create a new user, enter the following ~]# adduser ~]# adduser johnsmith Log in as the root user on the desired server. Therefore, I was thinking to create a process running as root which receives the request to kill processes from a user, checks if the user is allowed to start/stop the process and kills the process.CentOS 7, CentOS Stream 8, and CentOS Stream 9 If a second user allowed to do that wants to kill the process I'd like it to be allowed to do that but I don't want it to be sudoers. ![]() ![]() What I have is a list of users allowed to start the process, defined in the database, before starting the process I check that the current user in the list and, if yes, I start the process with the current user. ![]() ![]() Other users that are not in the group will not be able to start a second parallel process. The fact is that concurrent instances of the same process can be started from different users, that is why it is not convenient for me to set the group id to the process. Here, we’re going run the whoami command as the user mary. In a Linux environment, I need to kill a process which has been started by user2 if I am user1 without being sudoers or using root.ĭo you know if there is a way of setting that when launching the process? Such as a list of users allowed to kill the process? To use sudo to run a command as another user, we need to use the -u (user) option.
0 Comments
Leave a Reply. |