我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

用户集中管理-创新互联

使用/etc/sudoers里设置用户别名、命令别名来设置各个用户类型所需要的权限和命令来控制用户权限和所能使用的命令
主机别名
# Host_Alias FILESERVERS = fs1, fs2

创新互联公司是专业的格尔木网站建设公司,格尔木接单;提供网站建设、做网站,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行格尔木网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

用户别名
组别名

# User_Alias ADMINS = jsmith, mikem
# User_alias AdminsGroup=%xbin

命令别名
# Cmnd_Alias SOFTWARE = /bin/rpm, /usr/bin/up2date, /usr/bin/yum

配置
用户 主机=(主机) 命令
root ALL=(ALL) ALL

sudoers文件配置
[root@xbin-S ~]# grep -v "##" /etc/sudoers

# Host_Alias     FILESERVERS = fs1, fs2
# Host_Alias     MAILSERVERS = smtp, smtp2

# User_Alias ADMINS = jsmith, mikem

# Cmnd_Alias NETWORKING = /sbin/route, /sbin/ifconfig, /bin/ping, /sbin/dhclient, /usr/bin/net, /sbin/iptables, /usr/bin/rfcomm, /usr/bin/wvdial, /sbin/iwconfig, /sbin/mii-tool

# Cmnd_Alias SOFTWARE = /bin/rpm, /usr/bin/up2date, /usr/bin/yum

# Cmnd_Alias SERVICES = /sbin/service, /sbin/chkconfig

# Cmnd_Alias LOCATE = /usr/bin/updatedb

# Cmnd_Alias STORAGE = /sbin/fdisk, /sbin/sfdisk, /sbin/parted, /sbin/partprobe, /bin/mount, /bin/umount

# Cmnd_Alias DELEGATING = /usr/sbin/visudo, /bin/chown, /bin/chmod, /bin/chgrp 

# Cmnd_Alias PROCESSES = /bin/nice, /bin/kill, /usr/bin/kill, /usr/bin/killall

# Cmnd_Alias DRIVERS = /sbin/modprobe

# Defaults specification

#
# Refuse to run if unable to disable echo on the tty.
#
Defaults   !visiblepw

#
# Preserving HOME has security implications since many programs
# use it when searching for configuration files. Note that HOME
# is already set when the the env_reset option is enabled, so
# this option is only effective for configurations where either
# env_reset is disabled or HOME is present in the env_keep list.
#
Defaults    always_set_home

Defaults    env_reset
Defaults    env_keep =  "COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS"
Defaults    env_keep += "MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE"
Defaults    env_keep += "LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES"
Defaults    env_keep += "LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE"
Defaults    env_keep += "LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY"

#
# Adding HOME to env_keep may enable a user to run unrestricted
# commands via sudo.
#
# Defaults   env_keep += "HOME"

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin

root    ALL=(ALL)   ALL
xbin    ALL=(ALL)   ALL

# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS

# %wheel    ALL=(ALL)   ALL

# %wheel    ALL=(ALL)   NOPASSWD: ALL

# %users  ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom

# %users  localhost=/sbin/shutdown -h now

#includedir /etc/sudoers.d
Defaults        logfile=/var/log/sudo.log

实战命令
批量建立用户

for user in chuji001 chuji002 chuji003 net001 senior001 manager001
do 
    useradd $user
    echo "111111" | passwd --stdin $user
done

for n in `seq 5`
do 
    useradd -g phpers php00$n
    echo "111111" | passwd --stdin php00$n
done

for user in kaifamanager001 seniorphpers
do
    useradd $user
    echo "111111" | passwd --stdin $user
done

sudoers 配置文件
Cmnd_Alias CY_CMD_1 = /usr/bin/free, /usr/bin/iostat ,/usr/bin/top, /bin/hostname, /sbin/ifconfig,/bin/netstat, /sbin/route

Cmnd_Alias GY_CMD_1 = /usr/bin/free, /usr/bin/iostat ,/usr/bin/top, /bin/hostname, /sbin/ifconfig,/bin/netstat, /sbin/route, /sbin/iptables, /etc/init.d/network, /bin/nice, /bin/kill/, /usr/bin/kill,/usr/bin/killall, /bin/rpm, /usr/bin/up2data, /user/bin/yum, /sbin/fdisk, /sbin/parted, /sbin/partprobe, /bin/mount, /bin/umount

Cmnd_Alias CK_CMD_1 = /usr/bin/tail /app/log*, /bin/grep /app/log*, /bin/cat, /bin/ls

Cmnd_Alias GK_CMD_1 = /sbin/service, /sbin/chkconfig, /bin/tail /app/log*, /bin/grep /app/log*, /bin/cat, /bin/ls, /bin/sh ~/scripts/deploy.sh

Cmnd_Alias GW_CMD_1 = /sbin/route, /sbin/ifconfig, /bin/ping, /sbin/dhclient, /usr/bin/net /sbin/iptables, /usr/bin/rfcomm, /usr/bin/wvdial, /sbin/iwconfig, /sbin/mii-tool, /bin/cat /var/log/*

User_Alias CHUJIADMINS = chuji001, chuji002, chuji003

User_Alias GWNETADMINS = net001

User_Alias CHUJI_KAIFA = %phpers

Runas_Alias OP = root

senior001   ALL=(OP)    GY_CMD_1
manager001  ALL=(ALL)   NOPASSWD:ALL
kaifamanager001 ALL=(ALL) ALL,  /usr/bin/passwd [A-Za-z]*,!/usr/bin/passwd root, !/usr/sbin/visudo, ~/usr/bin/vi *sudoer*
seniorphpers    ALL=(OP)    GK_CMD_1
CHUJIADMINS     ALL=(OP)    CY_CMD_1
GWNETADMINS ALL=(OP)    GW_CMD_1
CHUJI_KAIFA ALL=(OP)    CK_CMD_1

批量创建20个用户,并设置密码为用户后随机5位数
[root@xbin-S ~]# cat test5.sh

#!/bin/bash

export PTAH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
for n in `seq 20`
do
        useradd user$n
        echo "user$n`echo user$n|md5sum | cut -c1-5`" | passwd --stdin user$n
        echo "user$n:user$n`echo user$n|md5sum | cut -c1-5`" >> /tmp/user_passwd.txt
        #echo "user$n`echo user$n|md5sum | cut -c1-5`"
done

网站题目:用户集中管理-创新互联
标题网址:http://shouzuofang.com/article/hpdji.html

其他资讯