day03-01 Amin linux-user and Group management

Source: Internet
Author: User

day03-01 Amin linux-user and Group management

3.1 User profile and password configuration files

/etc/passwd  用户信息配置文件/etc/shadow  用户密码配置文件        [[email protected] tmp]# cat /etc/passwd        root:x:0:0:root:/root:/bin/bash        bin:x:1:1:bin:/bin:/sbin/nologin        .............................        user1:x:1000:1000::/home/user1:/bin/bash        aming:x:1001:1001::/home/aming:/bin/bashusername: :uid:gid:注释:家目录:shell        [[email protected] tmp]# cat /etc/shadow        root:$6$Nat9OJRo$0qg5VdrCwNmGzXu8BXpu/mHfyRIE52/Vq1BuaOfiAYuA/14tPVv9S2QRYWUxWx0F9DXsIXM        9ESeZ42NoEJgJ40:17586:0:99999:7:::bin:*:17110:0:99999:7:::        ............................        user1:!!:17587:0:99999:7:::        aming:!!:17587:0:99999:7:::username:加密的密码:最近更改密码的日期1970-更改密码的时间:多少天之后才可以更改密码:密码多少天后到期,多少天之内更改密码:密码到期前的警告天数:账号失效期限:账号在此日期前可以使用:保留字段

3.2 User Group Management

/etc/group    组信息配置文件/etc/gshadow  组密码配置文件groupadd  grp1        [[email protected] tmp]# groupadd  grp1        [[email protected] tmp]# groupadd -g 1005 grp2groupdel grp1        [[email protected] tmp]# groupdel grp2        [[email protected] tmp]# tail -n2 /etc/group        slocate:x:21:        grp1:x:1002:        [[email protected] tmp]# groupdel usr1        groupdel:“usr1”组不存在        [[email protected] tmp]# groupdel user1        groupdel:不能移除用户“user1”的主组删除用户组,不可以删除有用户存在的组

3.3 User Management

Useradd-u Specify uid-g Specify gid-d Specify home directory name-s specify shell-m do not create home directory [[email protected] tmp]# Useradd User2 [[email protected] tmp]# tail-n2/etc/passwd aming:x:1001:1001::/home/aming:/bin/bash US Er2:x:1002:1003::/home/user2:/bin/bash [[email protected] tmp]# useradd-u 1004-g grp1 user3 [[EMAIL&N Bsp;protected] tmp]# tail-n3/etc/passwd aming:x:1001:1001::/home/aming:/bin/bash user2:x:1002:1003::/home/ User2:/bin/bash User3:x:1004:1002::/home/user3:/bin/bash [[email protected] tmp]# useradd-u 1006-g gr p1-d/home/aming111-s/sbin/nologin user4 [[email protected] tmp]# tail-n3/etc/passwd user2:x:1002: 1003::/home/user2:/bin/bash User3:x:1004:1002::/home/user3:/bin/bash User4:x:1006:1002::/home/aming111:/sbin        /nologin [[email protected] tmp]# useradd-m user5 [[email protected] tmp]# tail-n3/etc/passwd USER3:X:1004:1002::/home/user3:/bin/bash user4:x:1006:1002::/home/aming111:/sbin/nologin user5:x:1007:1007::/home/user5:/bin/b Ash [[email protected] tmp]# ls/home/aming aming111 user1 user2 user3userdel Delete user does not delete user home directory- R Delete User Delete home directory at the same time [[email protected] tmp]# userdel user8 [[email protected] tmp]# ls/home/am ing aming111 user1 user2 user3 User8

3.4 Usermod Changing user properties

usermod     -u 1006 username    -g 1009 username    -d /home/name    -s /sbin/nologin    -G user1,grp1,aming    -g user1

3.5 User Password Management

passwd    -l username  锁定用户密码    -u username  解锁用户密码usermod -L username  锁定用户密码usermod -U username  解锁用户密码        echo "123456"|passwd --stdin username  更改用户密码        [[email protected] tmp]# echo -e "123\nsss"        123        sss        [[email protected] tmp]# echo -e "123\tsss"        123 sss

3.6 mkpasswd

Make passwd
Yum Install-y expect

    [[email protected] tmp]# mkpasswd    xOW9ga[f7    [[email protected] tmp]# mkpasswd -l 12    gzcM37qhxuV|    [[email protected] tmp]# mkpasswd -l 12 -s 3    kmK).4o~zu2F    [[email protected] tmp]# mkpasswd -l 12 -s 0    ojmt8UhyB3do

3.7 su Command

su -  加载完整的环境变量和配置文件su - -c "touch /tmp/aming.111" aming  以aming运行命令        [[email protected] tmp]# ls -la /etc/skel/        总用量 24        drwxr-xr-x.  2 root root   62 2月  24 22:18 .        drwxr-xr-x. 74 root root 8192 2月  26 00:14 ..        -rw-r--r--.  1 root root   18 8月   3 2017 .bash_logout        -rw-r--r--.  1 root root  193 8月   3 2017 .bash_profile        -rw-r--r--.  1 root root  231 8月   3 2017 .bashrc

3.8 sudo command

Authorizing a normal user to execute a command [[email protected] tmp]# Visudo # allow ROOT to run any commands anywhere root AL L= (All) all aming all= (All)/usr/bin/ls,/usr/bin/mv,/usr/bin/cat amings all= (All) Nopas SWD:/usr/bin/su # # Host Aliases # Groups of machines.        Prefer to use Hostnames (perhaps using # wildcards for entire domains) or IP addresses instead.  # Host_alias fileservers = FS1, FS2 # Host_alias mailservers = SMTP, SMTP2 # User Aliases # # These aren ' t often necessary, as can use regular groups # # (ie, from files, LDAP, NIS, etc) in this File-jus t use%groupname # # rather than Useralias # User_alias ADMINS = jsmith, mikem amings_alias ADMINS = u Ser1,user2 # # Command Aliases # These is groups of related commands ... # # # Networking # Cmnd_ Alias NETWORKING =/sbin/route,/sbin/ifconfig,/bin/ping,/sbin/dhclient,/usr/b in/net,/sbin/iptables,/usr/bin/rfcomm,/usr/bin/wvdial,/sbin/iwconfig,/sbin/mii-tool # # Installation        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/b in/systemctl stop,/usr /bin/systemctl Reload,/usr/bin/systemctl restart,/usr/bin/systemctl status,/usr/bin/systemctl Enable,/usr/bin/ Systemctl Disable # Updating The Locate database # Cmnd_alias locate =/usr/bin/updatedb [[Email&nbs P;protected] ~]$ sudo/usr/bin/ls/root/[[email protected] ~]$ sudo/usr/bin/cat/root/

3.9 Restricting root Telnet

Local login cannot be restricted

    [[email protected] tmp]# vi /etc/ssh/sshd_config    #LoginGraceTime 2m    PermitRootLogin no

day03-01 Amin linux-user and Group management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.