Methods for ordinary users to execute commands that require root privileges

Source: Internet
Author: User

We often need to let ordinary users do the work that requires root permissions, such as ordinary users with the date command to modify the system dates. The date command requires root permission to execute, and 2 ways to solve the problem:

Method One:

Executed by root user chmod 4755/bin/date

Note: the addition of the S-permission bit to the date command sets setuid (4000) so that ordinary users can execute the date command, and the disadvantage is obvious, which is equivalent to removing the root permission limit of the date command.

Method Two:

Shell Script Packers:

#include "stdio.h"
#include "Pwd.h"
Main (int Argc,char *argv[])
{
struct passwd *srcc_pwd;
Char *proc_name = "sh./myfile.sh");

gid_t Srcc_gid;
uid_t Srcc_uid;
int Gg,uu;

Srcc_pwd=getpwnam ("root");
srcc_gid=srcc_pwd->pw_gid;
srcc_uid=srcc_pwd->pw_uid;
Gg=setgid (Srcc_gid);
Uu=setuid (SRCC_UID);
Gg=system (Proc_name);

Return
}

The root user compiles the file to generate the executable file a.out, and chmod 4111./a.out

This allows the normal user to complete the task by executing the./a.out (the task to be completed is written in the./myfile.sh script)



Methods for ordinary users to execute commands that require root privileges

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.