[root@localhost ~]# who |cut -d' ' -f1|sort|uniq
centos
root
[root@localhost ~]# id `who |tail -1|cut -d' ' -f1`
uid=0(root) gid=0(root) groups=0(root)
[root@localhost ~]# cut -d':' -f7 /etc/passwd|sort|uniq -c|tr -s ' '|sort -n -t' ' -k2|tail -1|cut -d' ' -f3
/sbin/nologin
[root@localhost ~]# sort -n -t':' -k3 /etc/passwd|tail|tr 'a-z' 'A-Z' > /tmp/maxusers.txt
[root@localhost ~]# ifconfig eth0|head -2|tail -1|tr -s ' '|cut -d':' -f2|cut -d ' ' -f1
192.168.1.108
[root@localhost ~]# find /etc -name "*.conf" -exec basename {} \; | tr 'a-z' 'A-Z' > /tmp/etc.conf
[root@localhost ~]# find /var -maxdepth 1 | grep -v "^/var$" | wc -l
17
[root@localhost ~]# sort -n -t':' -k3 /etc/group|head|cut -d':' -f1
root
bin
daemon
sys
adm
tty
disk
lp
mem
kmem
[root@localhost ~]# cat /etc/fstab /etc/issue > /tmp/etc.test
[root@localhost ~]# groupadd -r -g 306 mysql
[root@localhost ~]# tail -1 /etc/group
mysql:x:306:
+ -n 修改组名
[root@localhost ~]# groupdel mysql
[root@localhost ~]# ls -A /etc/skel
.bash_logout .bash_profile .bashrc
[root@localhost ~]# cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin
[root@localhost ~]# groupadd -r -g 306 mysql
[root@localhost ~]# useradd -r -g mysql -u 306 -M -s /sbin/nologin mysql
[root@localhost ~]# id mysql
uid=306(mysql) gid=306(mysql) groups=306(mysql)
[root@localhost ~]# userdel -r mysql
userdel: mysql mail spool (/var/spool/mail/mysql) not found
userdel: mysql home directory (/home/mysql) not found
echo "hello" | passwd --stdin docker &> /dev/null
echo $?
[root@localhost ~]# id
uid=0(root) gid=0(root) groups=0(root)
[root@localhost ~]# gpasswd -a mysql root
Adding user mysql to group root
[root@localhost ~]# id
uid=0(root) gid=0(root) groups=0(root)
[root@localhost ~]# su - mysql
Last login: Sat May 19 22:14:58 CST 2018 on pts/0
[mysql@localhost ~]$ id
uid=1000(mysql) gid=1000(mysql) groups=1000(mysql),0(root)
[mysql@localhost ~]$ ll
total 4
-rw-rw-r-- 1 mysql mysql 5 May 19 22:15 a.txt
-rw-rw-r-- 1 mysql mysql 0 May 19 22:15 b.txt
[mysql@localhost ~]$ touch c.txt
[mysql@localhost ~]$ ls
a.txt b.txt c.txt
[mysql@localhost ~]$ ll
total 4
-rw-rw-r-- 1 mysql mysql 5 May 19 22:15 a.txt
-rw-rw-r-- 1 mysql mysql 0 May 19 22:15 b.txt
-rw-rw-r-- 1 mysql mysql 0 May 19 22:17 c.txt
[mysql@localhost ~]$ newgrp root
[mysql@localhost ~]$ id
uid=1000(mysql) gid=0(root) groups=0(root),1000(mysql)
[mysql@localhost ~]$ touch d.txt
[mysql@localhost ~]$ ll
total 4
-rw-rw-r-- 1 mysql mysql 5 May 19 22:15 a.txt
-rw-rw-r-- 1 mysql mysql 0 May 19 22:15 b.txt
-rw-rw-r-- 1 mysql mysql 0 May 19 22:17 c.txt
-rw-r--r-- 1 mysql root 0 May 19 22:17 d.txt
[root@localhost ~]# chage -l root
Last password change : never
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7
[root@localhost ~]# id
uid=0(root) gid=0(root) groups=0(root)
[root@localhost ~]# id -u
0
[root@localhost ~]# id -g
0
[root@localhost ~]# id -G
0
[root@localhost ~]# su - mysql -c 'id'
uid=1000(mysql) gid=1000(mysql) groups=1000(mysql)
[root@localhost ~]# whoami
root
[root@localhost ~]# pwck
user 'ftp': directory '/var/ftp' does not exist
pwck: no changes
[root@localhost ~]# grpck
[root@localhost ~]# groupadd -g 2016 distro
[root@localhost ~]# tail -1 /etc/group
distro:x:2016:
[root@localhost ~]# useradd -u 1005 -g distro mandirva
[root@localhost ~]# tail -1 /etc/passwd
mandirva:x:1005:2016::/home/mandirva:/bin/bash
[root@localhost ~]# useradd -u 1100 -d /home/linux mageia
[root@localhost ~]# tail -1 /etc/passwd
mageia:x:1100:1100::/home/linux:/bin/bash
[root@localhost ~]# echo "mageedu"|passwd --stdin mageia
Changing password for user mageia.
passwd: all authentication tokens updated successfully.
[root@localhost ~]# userdel mandirva
[root@localhost ~]# ll -d /home/mandirva/
drwx------ 2 1005 distro 62 May 28 18:54 /home/mandirva/
[root@localhost ~]# groupadd peguin
[root@localhost ~]# useradd -u 2002 -g distro -G peguin slackware
[root@localhost ~]# tail -1 /etc/group
peguin:x:2017:slackware
[root@localhost ~]# tail -1 /etc/passwd
slackware:x:2002:2016::/home/slackware:/bin/bash
[root@localhost ~]# yum -y install tcsh
[root@localhost ~]# cat /etc/shells
/bin/sh
/bin/bash
/sbin/nologin
/usr/bin/sh
/usr/bin/bash
/usr/sbin/nologin
/bin/tcsh
/bin/csh
[root@localhost ~]# usermod -s /bin/tcsh slackware
[root@localhost ~]# grep "slackware" /etc/passwd
slackware:x:2002:2016::/home/slackware:/bin/tcsh
“`
[root@localhost ~]# groupadd admins
[root@localhost ~]# usermod -a -G admins slackware
[root@localhost ~]# id slackware
uid=2002(slackware) gid=2016(distro) groups=2016(distro),2017(peguin),2018(admins)
本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/99664
评论列表(1条)
很不错。命令建议格式化一下。