CentOS 7 用戶以及組管理常見解決問題

Listen

1.列出當前系統上所有已經登錄的用戶的用戶名,注意:同一個用戶登錄對此,則只顯示一次即可

[root@bogon ~]# who | cut -d’ ?‘ -f1|uniq
root

2.取出最后登錄到當前系統的用戶的相關信息

[root@localhost ~]# w
04:26:19 up 5:21, 1 user, load average: 0.08, 0.02, 0.01
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 192.168.1.113 23:05 0.00s 0.21s 0.06s w

3.取出當前系統上被用戶當作其默認shell的最多的那個shell

[root@localhost ~]# sort -t: -k7 /etc/passwd | cut -d: -f7 | uniq -c | sort -rn | head -1 | cut -c 9-

4.將/etc/passed/中的第三個字段數值最大的后10個用戶的信息全部改為大寫后保存至/tmp/maxusers.txt中

[root@localhost ~]# sort -t: -k3 -n /etc/passwd | tail -10 | tr ‘a-z‘ ‘A-Z‘ > /tmp/maxusers.txt
[root@localhost ~]# cat /tmp/maxusers.txt
POSTFIX:X:89:89::/VAR/SPOOL/POSTFIX:/SBIN/NOLOGIN
NOBODY:X:99:99:NOBODY:/:/SBIN/NOLOGIN
SASLAUTH:X:499:76:”SASLAUTHD USER”:/VAR/EMPTY/SASLAUTH:/SBIN/NOLOGIN
TEST:X:500:500::/HOME/TEST:/BIN/BASH
LISTEN:X:501:501::/HOME/LISTEN:/BIN/TCSH
A:X:502:502::/HOME/A:/BIN/BASH
B:X:503:503::/HOME/B:/BIN/BASH
C:X:504:504::/HOME/C:/BIN/BASH
MAGEIA:X:1100:1100::/HOME/LINUX:/BIN/BASH
SLACKWARE:X:2002:2016::/HOME/SLACKWARE:/BIN/TCSH
[root@localhost ~]#

5.取出當前主機的IP地址,提示,對ifconfig命令的結果進行切分

[root@localhost ~]# ifconfig | egrep -o “inet ([0-9.]+)” | cut -d” ” -f2

6.列出/etc/目錄下所有以.conf結尾的文件的文件名,并將其名字轉換為大寫后保存至/tmp/etc.conf文件中

find /etc/ -name “*.conf” | tr ‘a-z‘ ‘A-Z‘ > /tmp/etc.conf
cat /tmp/etc.conf

7.顯示/var目錄下一級子目錄或文件的總個數

[root@localhost ~]# ls -d /var/* | wc -l
16

8.取出/etc/group文件中第三個字段數值最小的10個組的名字

[root@localhost ~]# sort -t: -k3 -n /etc/group | cut -d: -f1 | head
root
bin
daemon
sys
adm
tty
disk
lp
mem
kmem

9.將/etc/fstab和/etc/issue文件的內容合并為同一個內容后保存至/tmp/etc.test文件中

[root@localhost ~]# cat /etc/fstab /etc/issue &> /tmp/etc.test
[root@localhost ~]# cat /tmp/etc.test

#
# /etc/fstab
# Created by anaconda on Mon Sep 18 01:25:11 2017
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk’
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=92316d57-6dc5-45aa-83ae-801037e14eb4 / ext4 defaults 1 1
UUID=c6870226-bc06-4545-aed9-381c0d974a23 /boot ext4 defaults 1 2
UUID=508c0af4-d750-4395-9167-2b41edc42242 /home ext4 defaults 1 2
UUID=aededa68-1ac4-4071-a952-198c93f8deb7 swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
CentOS release 6.5 (Final)
Kernel \r on an \m

10.請總結描述用戶和組管理累命令的使用方法并完成以下練習:

(1)、創建組distro,其GID為2016

[root@localhost ~]# groupadd -g 2016 distro
[root@localhost ~]# tail -2 /etc/group
c:x:504:
distro:x:2016:

(2)、創建用戶mandriva,其ID號為1005,基本組為distro

[root@localhost ~]# useradd -u 1005 -g distro mandriva
[root@localhost ~]# tail -1 /etc/passwd
mandriva:x:1005:2016::/home/mandriva:/bin/bash
[root@localhost ~]# tail -1 /etc/group
distro:x:2016:
[root@localhost ~]#

(3)、創建用戶mageia,其ID號為1100,家目錄為/home/linux

[root@localhost ~]# useradd -u 1100 -d /home/linux mageia
[root@localhost ~]# tail -2 /etc/passwd
mandriva:x:1005:2016::/home/mandriva:/bin/bash
mageia:x:1100:1100::/home/linux:/bin/bash

(4)、給用戶mageia添加密碼,密碼為mageedu

[root@localhost ~]# passwd mageia
更改用戶 mageia 的密碼 。
新的 密碼:
無效的密碼: 它基于字典單詞
無效的密碼: 過于簡單
重新輸入新的 密碼:
passwd: 所有的身份驗證令牌已經成功更新。
[root@localhost ~]#

(5)、刪除mandriva,但保留其家目錄

[root@localhost ~]# userdel mandriva
[root@localhost ~]# ls -a /home/mandriva/
. .. .bash_logout .bash_profile .bashrc
[root@localhost ~]#

(6)、創建用戶slackware,其ID號為2002,基本組為distro,附加組為peguin

[root@localhost ~]# useradd -u 2002 -g distro -G peguin slackware
[root@localhost ~]# tail -2 /etc/group
mageia:x:1100:
peguin:x:2017:slackware

(7)、修改slackware的默認shell為/bin/tcsh

[root@localhost ~]# usermod -s /bin/tcsh slackware
[root@localhost ~]# tail -2 /etc/passwd
mageia:x:1100:1100::/home/linux:/bin/bash
slackware:x:2002:2016::/home/slackware:/bin/tcsh

(8)、為用戶slackware新增附加組admins

[root@localhost ~]# groupadd admins
[root@localhost ~]# usermod -G admins slackware
[root@localhost ~]# tail -2 /etc/group
peguin:x:2017:
admins:x:2018:slackware
[root@localhost ~]#

本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/100247

(0)
ListenListen
上一篇 2018-06-03
下一篇 2018-06-03

相關推薦

  • 第一標題

    第一摘要

    Linux筆記 2018-05-14
  • sed

    sed 過濾文件改文 ( 行編輯器)Sed 選項 腳本(地址命令)inputfile(要處理的文件名)-n 不輸出模式空間內容到屏幕,即不自動打印-e 多點編輯-f /PATH/SCRIPT_FILE: 從指定文件中讀取編輯腳本-r支持使用擴展正則表達式-i.bak 備份文件并遠處編輯 -i編輯文件不備份script ‘地址命令’不給地址: 對全部的所有行處…

    Linux筆記 2018-04-15
  • 第一周總結

    ?##### 存儲網絡: “` DAS—–直接連接存儲(Direct attached storage) NAS—–網絡連接存儲(Network attached storage) SAN—–存儲區域網絡(storage area network) “` &#82…

    Linux筆記 2018-04-01
  • 第九周 加密技術與域名系統

    1、簡述常見加密算法及常見加密算法原理,最好使用圖例解說? 2、搭建apache或者nginx并使用自簽證書實現https訪問,自簽名證書的域名自擬? 3、簡述DNS服務器原理,并搭建主–輔服務器 4、搭建并實現智能DNS    

    2018-02-01
  • elk

    轉載,供日后回查

    2018-07-31
  • 第二周

    反向單引號 ` `:執行能力強,可以執行命令 [等價于$()]單引號 ‘ ’:只顯示字符雙引號 “ ”:識別變量,不識別命令花括號{ }: 里面內容互相組合 打印重復字符串的簡化形式echo file{1,3,5} 顯示為file1.3.5rm -f file{1,3,5} 刪除file1.3.5echo file{1..10} 顯示為file1&#8230…

    Linux筆記 2018-07-29
欧美性久久久久