




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、來自:標點符的 Linux 學習筆記:用戶及用戶組鏈接: (點擊 尾部閱讀原文前往)Linux用戶只有兩個等級:root及非root。Linux中還有一部 分用戶,如: apache 、mysql 、nobody 、ftp 等,這些也都 是非 root 用戶,即普通用戶。 Linux 的權限實際是上不同用 戶所能訪問的文件的不同產生的假象。而這些假象的造成, 還要涉及到另外一個概念:用戶組一個用戶至少要屬于一個 用戶組一個用戶可以屬于多個用戶組 用戶組存在的原因主要還是方便分配權限。而用戶本身和權 限的差別不是很大,各個用戶之間主要的不同是:是否擁有 密碼 home 目錄(普通用戶可以有一個以
2、自己用戶名命名的 home 目錄,存放的地址是 /home/username ,root 用戶的 home 目錄是: /root )shell像 nobody 這樣用來執(zhí)行 Nginx 的工作進程的用戶,一般不 分配密碼和 shell ,甚至連 home 目錄都沒有。 為什么不分配密碼?如果設置了密碼,程序無法自動使用。 由于不會有人使用這個用戶登錄系統(tǒng),所以就沒有必要分配 shell 。( 備注:其實嚴格上說是有分配 shell ,只是分配的 shell 是/sbin/nologin 這個特殊的shell,沒有任何其他功能,主要功能是防止你登陸。 ) 所有用戶都可以通過查看 /etc/pas
3、swd 查看。以下為我的系 統(tǒng)中的用戶信息: root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/
4、sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin avahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoip
5、d:/sbin/nologin systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin systemd-network:x:998:996:systemd Network Management:/:/sbin/nologin dbus:x:81:81:System message bus:/:/sbin/nologinpolkitd:x:997:995:User for polkitd:/:/sbin/nologin tss:x:59:59:Account used by the trousers package to san
6、dbox the tcsd daemon:/dev/null:/sbin/nologin postfix:x:89:89:/var/spool/postfix:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin qw:x:1000:1000:qw:/home/qw:/bin/bash 文件的每一行代表著一個用戶,每一行由冒號“:”分割成 7 個字段,其結構如下:用戶名:密碼: UID : GID :用戶全 名: home 目錄: shellUID :UID 0 root 用戶 UID
7、1999 是 占坑用戶,即一寫無法登錄的用戶(以前是系統(tǒng)是 1499 , 最近剛改) UID 1000 以上是正常的可登錄用戶 GID :前面說了一個用戶可以屬于多個用戶組,但這里只有 一個,表示的是專職用戶組,即一個用戶只有一個專職用戶 組,其屬于其他用戶組的關聯(lián)關系存儲在 /etc/group 文件中。 其中比較特殊的是密碼字段,統(tǒng)一由 x 代替了,看 /etc/passwd 就知道一開始 Linux 是將密碼存在這個文件里 的,由于考慮到 /etc/passwd 可以被所有人查看,所以將統(tǒng) 一存儲到 /etc/shadow 文件(只有 root 權限可以訪問)中, 具體數據如下: roo
8、t:$6$yp9k7rTFRX76aFP/$RpQ0Q6SIFpKn5jA3vEmpzs MdMDqDjmKQY3qCcVyuVNa1dTOOwJqC0SWCxqsNrZgYiBf5Og94cDR97hGCfd0OX1:0:99999:7: bin:*:16659:0:99999:7: daemon:*:16659:0:99999:7: adm:*:16659:0:99999:7: lp:*:16659:0:99999:7: sync:*:16659:0:99999:7: shutdown:*:16659:0:99999:7: halt:*:16659:0:99999:7: mail:*:16
9、659:0:99999:7: operator:*:16659:0:99999:7: games:*:16659:0:99999:7: ftp:*:16659:0:99999:7: nobody:*:16659:0:99999:7: avahi-autoipd:!:17031: systemd-bus-proxy:!:17031: systemd-network:!:17031: dbus:!:17031: polkitd:!:17031: tss:!:17031: postfix:!:17031: sshd:!:17031: qw:$6$W1QYF2/.vMB7BPm/$n7GV1D07lc
10、VDhsyGS0xUe68loRTfmFj2vT4TkELQgQGfqDxNn2fGzBYUYj4CgZMhaiNSvvmhW4gubpQxBhr3H0:0:99999:7: 其結構如下:登錄 名:加密過的密碼( *代表此用戶不能用來登錄) :密碼最近 更改日期( linux 時間戳):最少密碼天數( 0 代表隨時可更 改):最多密碼天數:過期前幾天提醒用戶:密碼不可用期 限:賬戶過期日期:保留位再來看看 /etc/group 文件: root:x:0: bin:x:1: daemon:x:2: sys:x:3: adm:x:4: tty:x:5: disk:x:6: lp:x:7: mem:
11、x:8: kmem:x:9: wheel:x:10: cdrom:x:11: mail:x:12:postfix man:x:15: dialout:x:18: floppy:x:19:games:x:20: tape:x:30: video:x:39: ftp:x:50: lock:x:54: audio:x:63: nobody:x:99: users:x:100: utmp:x:22: utempter:x:35: ssh_keys:x:999: avahi-autoipd:x:170: input:x:998: systemd-journal:x:190: systemd-bus-pr
12、oxy:x:997: systemd-network:x:996: dbus:x:81: polkitd:x:995: dip:x:40: tss:x:59: postdrop:x:90: postfix:x:89:sshd:x:74:qw:x:1000:qw 其結構如下:組名:用戶組密碼: GID :用戶 組內的用戶名正常的使用中很少會用到用戶組密碼,其存儲 在 /etc/gshadow 中。 用戶組文件比較特特殊的是“”用戶組內的用戶名”,其實就是 這個組下的用戶列表,每個用戶之間用逗號“ , ”分割;本字段 可以為空; 如果字段為空表示用戶組為 GID 的用戶名普通用 戶的權限非常的低,
13、就連在系統(tǒng)里安裝軟件的權限都沒有, 很多時候可以臨時給普通用戶以特權,就是sudo (在命令前添加 sudo )。比如: sudo cat /etc/shadow 完成后需要您輸 入 root 的密碼,這樣 就可以假借 root 身份了, centos 默認 普通用戶是沒有 sudo 權限的,這與主要以桌面版為主的 Ubuntu 和 Fedora 不同, 如需給予用戶 root 特權, 就需要更 改/etc/sudoers 文件,修改內容。# Sudoers allowsparticular users to run various commands as# the root user, wi
14、thout needing the root password.# Examples are provided at the bottom of the file for collections # of related commands, which can then be delegated out to particular# users or groups.# # This file must be edited with the visudo command.# Host Aliases# Groups of machines. You may prefer to use hostn
15、ames (perhaps using# wildcards for entire domains) or IP addresses instead.# Host_AliasFILESERVERS = fs1, fs2# Host_AliasMAILSERVERS = smtp, smtp2# User Aliases# These arent often necessary, as you can use regular groups# (ie, from files, LDAP, NIS, etc) in this file - justuse %groupname# rather tha
16、n USERALIAS# User_Alias ADMINS = jsmith, mikem# Command Aliases# These are groups of related commands.# Networking# 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# Installa
17、tion and management of software# Cmnd_Alias SOFTWARE = /bin/rpm, /usr/bin/up2date,/usr/bin/yum# Services# Cmnd_Alias SERVICES = /sbin/service, /sbin/chkconfig, /usr/bin/systemctl start, /usr/bin/systemctl stop, /usr/bin/systemctl reload, /usr/bin/systemctl restart, /usr/bin/systemctl status, /usr/bi
18、n/systemctl enable, /usr/bin/systemctl disable# Updating the locate database# Cmnd_Alias LOCATE = /usr/bin/updatedb# Storage# Cmnd_Alias STORAGE = /sbin/fdisk, /sbin/sfdisk, /sbin/parted, /sbin/partprobe, /bin/mount, /bin/umount # Delegating permissions# Cmnd_Alias DELEGATING = /usr/sbin/visudo,/bin
19、/chown, /bin/chmod, /bin/chgrp# Processes# Cmnd_Alias PROCESSES = /bin/nice, /bin/kill,/usr/bin/kill, /usr/bin/killall# Drivers# Cmnd_Alias DRIVERS = /sbin/modprobe# Defaults specification# Disable ssh hostname sudo <cmd>, because it will show the password in clear.#You have to run ssh -t host
20、name sudo<cmd>.#Defaults requiretty# Refuse to run if unable to disable echo on the tty. This setting should also be# changed in order to be able touse sudo without a tty. See requiretty above.#Defaults !visiblepw# Preserving HOME has security implications since many programs# use it when sear
21、ching 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 theenv_keep list.# Defaults always_set_homeDefaults env_resetDefaults env_keep = COLO
22、RS DISPLAYHOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS Defaults env_keep = MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPEDefaults env_keep = LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGESDefaultsenv_keep = LC_MONETARY LC_NAMELC_NUMERIC LC_PAPER LC_TELEPHONEDefaults env_keep = LC_TIME LC
23、_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY# Adding HOME to env_keep may enable a user to run unrestricted# commands via sudo.# Defaultsenv_keep = HOME Defaultssecure_path = /sbin:/bin:/usr/sbin:/usr/bin# Next comes the main part: which users can run whatsoftware on# which machines (the sudoers fi
24、le canbe shared between multiple# systems).# Syntax:# user MACHINE=COMMANDS# The COMMANDS section may have other options added to it.# Allow root to run any commands anywhererootALL=(ALL) ALL# Allows members of the sys group to run networking, software,# service management apps and more.# %sys ALL =
25、 NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS # Allows people in group wheel to run all commands%wheel ALL=(ALL) ALL# Same thing without a password# %wheelALL=(ALL) NOPASSWD: ALL# Allows members of the users group to mount and unmount the# cdrom as root # %users AL
26、L=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom# Allows members of the users group to shutdown this system# %users localhost=/sbin/shutdown -h now# Read drop-in files from /etc/sudoers.d (the # here doesnot mean a comment)#includedir /etc/sudoers.d 給沒有用戶添加 sudo 特權,只需 參照 # Allow root to run any com
27、mands anywhere root ALL=(ALL) ALL 添加如下:# Allow root to run any commands anywhereroot ALL=(ALL) ALLqw ALL=(ALL) ALL 如果要給某個用戶組添加 sudo 特權則為:(與給用戶不同的是多了一個 %)# Allows people in group wheel to run all commands%wheel ALL=(ALL) ALL 另外一種方式是添加不需要輸入 root 密碼即有 root 權限的用戶,添加方法如下: qw ALL=(ALL) NOPASSWD:ALL 另外還可以設定到底有 哪些執(zhí)行權限,具體的規(guī)則如下: (具體可看 sudoers 配置 文件詳解)授權用戶 主機=(切換到哪些用戶或用戶組 ) 是 否需要密碼驗證 命令 1,(切換到哪些用戶或用戶組 ) 是否需要密碼驗證 命令 2,( 切換到哪些用戶或用戶組 ) 是否需 要密碼驗證 命令 3 另外默認情況下第一次使用 sudo 時,需要輸入 root 密碼,如果 5 分鐘內再次執(zhí)行 sudo 則無需再 輸入密碼,超過 5 分鐘則要重新輸入。這個時間也是可以進 行配置的,在 sudoers 中添加如
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 節(jié)能整車物流運輸計劃
- 《Unit 1 Hello!》(教學設計)-2024-2025學年冀教版(三起)(2024)英語三年級上冊
- 人教版高中物理選擇性必修第二冊第四章主題提升課(三)電磁振蕩與電磁波課件
- 全國浙教版信息技術七年級上冊第一單元第3課《互聯(lián)網應用體驗》教學設計
- 2025至2030年中國對乙酰氨基酚片數據監(jiān)測研究報告
- 2025至2030年中國頭孢唑啉鈉針劑數據監(jiān)測研究報告
- 2025至2030年中國塑鋼平開門窗數據監(jiān)測研究報告
- 2025至2030年中國噴發(fā)膠專用樹脂數據監(jiān)測研究報告
- 2025至2030年中國單相直流減壓器數據監(jiān)測研究報告
- 2025至2030年中國減壓器回火防止器數據監(jiān)測研究報告
- 工作室成員成長檔案模板(內部版)課件
- (完整版)馬克思主義基本原理概論知識點
- 弱電系統(tǒng)巡查記錄表(辦公樓)
- 預防接種人員崗位培訓習題(Ⅰ類培訓練習題庫共385題)
- 現(xiàn)場經濟簽證單范本
- 《網店運營與管理》課件(完整版)
- 《跨境電商B2B操作實務》教學大綱
- 河口區(qū)自然資源
- 精益改善項目管理制度
- 2012數據結構英文試卷A及答案
- 機翼結構(課堂PPT)
評論
0/150
提交評論