91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

linux中如何批量管理用戶和組

發布時間:2020-06-06 17:22:20 來源:億速云 閱讀:452 作者:Leah 欄目:系統運維

linux中如何批量管理用戶和組?這篇文章運用了實例代碼展示,代碼非常詳細,可供感興趣的小伙伴們參考借鑒,希望對大家有所幫助。

使用/etc/sudoers里設置用戶別名、命令別名來設置各個用戶類型所需要的權限和命令來控制用戶權限和所能使用的命令
主機別名
# Host_Alias     FILESERVERS = fs1, fs2

用戶別名
組別名

# 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

看完這篇文章,你們學會在linux中批量管理用戶和組了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀。


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

阿巴嘎旗| 井陉县| 东城区| 甘肃省| 金门县| 和平县| 泸定县| 霍山县| 隆尧县| 西丰县| 军事| 龙里县| 开江县| 新平| 营山县| 平凉市| 三门峡市| 邹城市| 威宁| 仙居县| 平度市| 田阳县| 邮箱| 屯留县| 克山县| 临邑县| 陆丰市| 永昌县| 广西| 柏乡县| 密云县| 昭觉县| 垫江县| 咸丰县| 商丘市| 福安市| 朝阳市| 石阡县| 九龙城区| 四会市| 大石桥市|