全部博文(1144)
分类: LINUX
2008-09-10 21:06:46
Why use sudo?
$ sudo passwd jimmyt
Logging
sudo determines whether a user is authorized to run a specific command as root by examining its configurations file, /etc/sudoers.
sudo config file /etc/sudoers sudo binary which prefaces each command,
sudo mount /mnt/distro /usr/bin/sudo sudo binary to edit suders file and check syntax,
sudo visudo /usr/sbin/visudo
# Machine aliases
Host_Alias SERVERS=ponto,oaxaca,colima
Host_Alias SCIENCE=curie,salk,pasteur
# Command aliases
Cmnd_Alias SHUT=/sbin/shutdown -r *
Cmnd_Alias DUMP=/sbin/dump,/sbin/restore
Cmnd_Alias SHELLS=/bin/sh,/bin/tcsh,/bin/bash,/bin/csh
Cmnd_Alias PRINT=/usr/sbin/lpc,/usr/sbin/lprm
# Privileges
ADMINS ALL=(ALL)ALL
STUDENTS ALL,!SERVERS=(operator)SHUT,DUMP
kelly ALL=NOPASSWD:PRINT
jimj,mikes SCIENCE=(ALL)ALL,!SHELLS
dylan goku=(ALL)ALL
After the aliases section (above), each permission line contains the following information
ADMINS ALL=(ALL)ALL
applies to the users in the alias ADMINS, pattyo and joel, on all machines, running as any user, can execute any command.
The second permission line:
STUDENTS ALL,!SERVERS=(operator)SHUT,DUMP
applies to the STUDENTS: tim, mary and jack, on all machines except the SERVERS: ponto, oaxaca and colima. They can execute the comands shutdown, dump and restore, only as the user operator. The command line they would use would be something like this:
$ sudo -u operator /sbin/dump 0u /dev/dha3
The forth permission line:
jimj,mikes SCIENCE=(ALL)ALL,!SHELLS
applies to the users jimj and mikes on the machines curie, salk and pasteur where they have permission to run all commands as any user except shells.
[kelly@ponto]$ sudo /usr/sbin/lpc reread lpExample: the user jack trying to run the shutdown command on the server ponto:
lpd server pid 1184 on ponto.example.com, sending SIGHUP
[jack@ponto]$ sudo /sbin/shutdown -h nowWe trust you have received the usual lecture from the local System Administrator. It usually boils down to these two things:
#1) Respect the privacy of others.
#2) Think before you type.Password:
jack is not allowed to run sudo on ponto. This incident will be reported.
Jack (see alias STUDENTS in configuration file) is excluded from all rootly privileges on the machine ponto.
Can you think of ways to circumvent the system?
[mikes@ponto]$ sudo /bin/sh
Password:
Sorry, user mikes is not allowed to execute '/bin/sh' as root on ponto.
[mikes@ponto]$ cp -p /bin/csh /tmp/csh
[mikes@ponto]$ sudo /tmp/csh
[root@ponto]$ whoami
root
# rpm -qa sudoCreate the group admin on your machines
# groupadd adminMake sure that your account is in the admin group
# usermod -G admin youracctCreate a student account (if it doesn't already exist)
# useradd studentPut the student account in the additional group users
# usermod -G users studentCheck the /etc/passwd and /etc/group files for your modifications
# grep admin /etc/groupModify the /etc/sudoers file using the visudo command
# grep youracct /etc/passwd
# visudo