d2 - user and group management

文件管理:
    cp,mv,rm
cp 
[root@izm5e5qf7n47jhwufk5eo9z ~]# cp --help
         Usage: cp [OPTION]... [-T] SOURCE DEST
         or:  cp [OPTION]... SOURCE... DIRECTORY
         or:  cp [OPTION]... -t DIRECTORY SOURCE...

           Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.


 cp SRC DEST  
         If the copied file does not exist, create a new DEST and fill the contents of SRC into DEST.
If the directory exists ,
         if DEST is a file: overwrite the contents of SRC to DEST.
       At this time, it is recommended to use the -i option for the cp command.
  If DEST is a directory: Create a new file with the same name as the original file under DEST, and fill the contents of SRC into the new file




cp SRC... DEST DEST
    src.. is multiple files must exist and is a directory, otherwise it is wrong cp SRC DEST      SRC is a directory  To use -r recursive copy              if DEST does not exist: create the specified directory, then copy S if DEST exists:           if it is a file error







  is the directory:

Common options
     -i interactive rm     -f force -r recursive rm -rf / text editor nano           nano a.txt   full screen editor basic features of bash       1. command alias (alias)        2. alias NAME='VALUE'                define alias NAME , which is equivalent to executing the command value    Note: It is only valid for the current shell process. If it needs to be permanently valid, it must be defined in the configuration file            only for the current user. ~/.hashrc is             valid for all users: After /etc/bashhrc is            modified, the configuration file must be re-read              source /path/to/config_file        revoke the alias unalias       2. File name wildcard glob       wildcard *, ? , []    1 *      any character of any length   a*b              2 ?               Any one character               a?b             3 [] matches any single character in the range
 
 




 



 

    







   

        









                [0-9] 0-9 pick one
                 [az] case insensitive
                 [AZ] uppercase
                  ^ match any single character outside the specified range           [^0-9] any single character outside 0-9 practice     [root@izm5e5qf7n47jhwufk5eo9z ~ ]# ls -d /var/l*[0-9]*[[:lower:]]    [root@izm5e5qf7n47jhwufk5eo9z ~]# ls -d /tmp/l*[0-9]*[[:lower:] ] / tmp   / labc8m ctrl+a Jump to the beginning of the command         ctrl +e Jump to the end ctrl+c Cancel O redirection changes the standard position output redirection: COMMMAND>NEW_POS, COMMAND>>NEW_POS                       override redirection append redirection set -c disable override redirection 2> override redirection error output stream 2 >> append redirection error output data stream  
     
  


   
   






  
  





     






[root@izm5e5qf7n47jhwufk5eo9z ~]# tail -100 /etc/rc.d/rc.sysiiiinit > /tmp/sysinit.out 2> /tmp/sysinit.err
[root@izm5e5qf7n47jhwufk5eo9z ~]# cat /tmp/sysinit.err
tail : cannot open – etc/rc.d/rc.sysiiiinit – for reading: No such file or directory
[root@izm5e5qf7n47jhwufk5eo9z 
    
         COMMAND > /path/to/file.out 2>&1
  COMMAND >> /path/to/file.out 2>>&1    input redirection <          tr convert or delete characters tr    [root@izm5e5qf7n47jhwufk5eo9z ~]# tr abc ABC abcdef ABCdef output is converted to uppercase [root@izm5e5qf7n47jhwufk5eo9z ~]# tr 'az' 'AZ' < /etc/fstab # # /ETC/FSTAB # CREATED BY ANACONDA ON SUN OCT 15 15:19:00 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=EB448ABB-3012 -4D8D-BCDE-94434D586A31 / EXT4 DEFAULTS 1 1 delete [root@izm5e5qf7n47jhwufk5eo9z ~]# tr -d aa aasfsa sfs input a large number of characters save to /tmp/test.out receive EOF character end [root@izm5e5qf7n47jhwufk5eo9z ~]# cat >> /tmp/test.out<<EOF > SDFS > SDFS > SDFG > EOF pipe    COMMAND1| COMMAND2 | COMMAND3|..  [root@izm5e5qf7n47jhwufk5eo9z ~]# echo "$PATH" | tr 'az' 'AZ' /USR/LOCAL /SBIN:/USR/LOCAL/BIN:/USR/SBIN:/USR/BIN:/ROOT/BIN


















   



[root@izm5e5qf7n47jhwufk5eo9z ~]# echo "$PATH" | tr 'a-z' 'A-Z' | tr -d 'U'

/SR/LOCAL/SBIN:/SR/LOCAL/BIN:/SR/SBIN:/SR/BIN:/ROOT/BIN


tee command Standard output and save a copy to the specified path
   [root@izm5e5qf7n47jhwufk5eo9z ~]# tee /tmp/tee.out
1
1
234
234
34
34
^C
[root@izm5e5qf7n47jhwufk5eo9z ~]# cat /tmp/tee.out
1
234
34
Exercise 22222222
1     
[root@izm5e5qf7n47jhwufk5eo9z ~]# head -n 5 /etc/passwd | tr 'az' 'AZ' |tee>/tmp/passwd.out
[root@izm5e5qf7n47jhwufk5eo9z ~]# cat /tmp/passwd.out
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
[root@izm5e5qf7n47jhwufk5eo9z 


2
[root@izm5e5qf7n47jhwufk5eo9z ~]# who | tail -n 3| tr 'az' 'AZ' >/tmp/who.out
[root@izm5e5qf7n47jhwufk5eo9z ~]# cat /tmp/who.out
ROOT PTS/3 2018-04- 13 19:29 (114.227.229.194)
ROOT PTS/4 2018-04-13 20:13 (114.227.229.194)
ROOT PTS/5 2018-04-13 20:32 (114.227.229.194)


Text processing tools wc ,cut, sort,uniq
 wc  
    -l
    -w
-c 




[root@izm5e5qf7n47jhwufk5eo9z ~]# wc /etc/passwd
  25 35 1104 /etc/passwd
  
  lines word count bytes
  
 [root@izm5e5qf7n47jhwufk5eo9z ~]# ifconfig | wc -l
16


cut 
   -d 
   
   
   linux User Rights Management
Resource Assignment
       Authentication: Authentication
    Authorization Authorization
        Accounting: Audit
      Audition
linux User Username/UID
Administrator: root 0
Ordinary User: 1-65535
System User: 1-499
Daemon Obtaining Resources for Permission Assignment
Login User: 500+
           Interactive Login Linux Group Groupname/GID Administrator Group: root,0 common group:  system group: 1-499                   common group: 500+     Linux security context:          running program: process (process)                 running as the initiator of the process:                        root:cat                        tom:cat                  everything that the process can access Resource permissions depend on the identity of the initiator of the process,     the category of the linux group, the         user's basic group (main group), the group name is the same as the user name: and only contains one user's private group,         the user's additional group (extra group) linux user and group related configuration files           /ect/passwd User and their attribute information (name UID base group)
 











    




       


          /ect/group group and its attributes
          /etc/shadow user password and its related attributes
          /etc/gshadow group password and its related attributes






    /etc/passwd
    user1:x:1001:1001::/home/user1:/bin/bash
name:passwd:UID:GID:GECOS:directory:shellusername:passwd:UID:GID
:GECOS:home directory:default shell /etc/group wheel:x:10: groupname:grouppassword :GID:with the current group List of users for additional groups (multiple separated by, ) /etc/shadow        username: encrypted password: date of last password change: minimum password age: maximum password age: password warning period: password disabled of: account expires: reserved field Tom: I3mySRML $ $ $. 6 v4WDRwje6Q36JbJHjkQegqogDAyxmO4aTqgKBPAB1PDKIEFD6n.7v9iduFgY2FsUP1NtZGa / KIZiMaOHgEvCT0: 17634: 0: 99999: :::. 7    [izm5e5qf7n47jhwufk5eo9z the root @ ~] # the useradd user2 [izm5e5qf7n47jhwufk5eo9z the root @ ~] # tail -1 / etc/passwd user2:x:1004:1004::/home/user2:/bin/bash






   
    
   



[root@izm5e5qf7n47jhwufk5eo9z ~]# tail -1 /etc/group
user2:x:1004:
[root@izm5e5qf7n47jhwufk5eo9z ~]# tail -1 /etc/shadow
user2:!!:17634:0:99999:7:::
[ root@izm5e5qf7n47jhwufk5eo9z ~]#User 


and group related management commands
User creation: useradd
      useradd 
        -u UID:[UID_MIN-UID_MAX], defined in /etc/login.defs
-g GID: indicates that the basic group to which the user belongs can be a group name or a group name For GID
            -c "COMMIT" comment
                     -d specify home directory
  -s specify shell path
  -G specify that additional groups must exist
-r create system group
     CenOS7 id<1000 [root@izm5e5qf7n47jhwufk5eo9z ~]# groupadd mygrp [root@izm5e5qf7n47jhwufk5eo9z ~]# tail -1 /etc/group mygrp:x:1005: [root@izm5e5qf7n47jhwufk5eo9z ~]# useradd -g mygrp user3





[root@izm5e5qf7n47jhwufk5eo9z ~]# tail -1 /etc/passwd
user3:x:1005:1005::/home/user3:/bin/bash[root@izm5e5qf7n47jhwufk5eo9z ~]# id user3uid=1005(user3) gid=1005(mygrp) groups=1005(mygrp)-d[root@izm5e5qf7n47jhwufk5eo9z ~]# useradd -d /home/ttt  user5useradd: user 'user5' already exists[root@izm5e5qf7n47jhwufk5eo9z ~]# useradd -d /home/ttt  userr4[root@izm5e5qf7n47jhwufk5eo9z ~]# tail -1 /etc/passwduserr4:x:1008:1008::/home/ttt:/bin/bash-c[root@izm5e5qf7n47jhwufk5eo9z ~]# useradd -c "useroooo" user4[root@izm5e5qf7n47jhwufk5eo9z ~]# tail -1  /etc/passwduser4:x:1007:1007:useroooo:/home/user4:/bin/bash-G
















[root@izm5e5qf7n47jhwufk5eo9z ~]# useradd -G mygrp user7
[root@izm5e5qf7n47jhwufk5eo9z ~]# id user7
uid=1009(user7) gid=1009(user7) groups=1009(user7),1005(mygrp)


[root@izm5e5qf7n47jhwufk5eo9z ~]# groupadd -g 3000 testgrp
[root@izm5e5qf7n47jhwufk5eo9z ~]# tail -1 /etc/group
testgrp:x:3000:-r[root@izm5e5qf7n47jhwufk5eo9z ~]# groupadd -r sql[root@izm5e5qf7n47jhwufk5eo9z ~]# tail -1 /etc/groupsql:x:995:查看用户 id信息-u UID-g GID -G Groups -n  name[root@izm5e5qf7n47jhwufk5eo9z ~]# id tomuid=1002(tom) gid=1002(tom) groups=1002(tom)[root@izm5e5qf7n47jhwufk5eo9z ~]# id -u tom1002
















[root@izm5e5qf7n47jhwufk5eo9z ~]# id -g tom
1002
[root@izm5e5qf7n47jhwufk5eo9z ~]# id -r tom
id: cannot print only names or real IDs in default format
[root@izm5e5qf7n47jhwufk5eo9z ~]# id -G TOM
id: TOM: no such user
[root@izm5e5qf7n47jhwufk5eo9z ~]# id -G tom
1002     to switch users or execute commands as other users: su       to switch users         su username non-login switching will not read the target user's configuration file su - username login Switching will read the user's configuration file root su to other users without a password, when non-root users switch to [root@izm5e5qf7n47jhwufk5eo9z ~]# su tom [tom@izm5e5qf7n47jhwufk5eo9z root]$ echo $PATH /usr/local/sbin:/usr /local/bin:/usr/sbin:/usr/bin:/root/bin [tom@izm5e5qf7n47jhwufk5eo9z root]$ exit






 




[root@izm5e5qf7n47jhwufk5eo9z ~]# su - user7
[user7@izm5e5qf7n47jhwufk5eo9z ~]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/ user7/.local/bin:/home/user7/bin Encryption mechanism:         encryption: plaintext --> ciphertext one-way encryption: extract data fingerprint md5: 128bit sha1 160bit user attribute modification usermod       -d   -u UID   -g GID    -G Additional group The original group will be overwritten. If you keep the original, you must use -a at the same time to add   -s to the new default shell   -c note   -d new home directory The files in the original home directory will not be moved to the new home directory at the same time. If you want to move, use both -m   -l new login   [root@izm5e5qf7n47jhwufk5eo9z ~]# groupadd g1   [root@izm5e5qf7n47jhwufk5eo9z ~]# groupadd g2   [root@izm5e5qf7n47jhwufk5eo9z ~]# tail -1 /etc/group   g2:x:3002:



   
   




 
 










  




  [root@izm5e5qf7n47jhwufk5eo9z ~]# usermod -G g2,g1 tom
  [root@izm5e5qf7n47jhwufk5eo9z ~]# id tom
  uid=1002(tom) gid=1002(tom) groups=1002(tom),3001(g1),3002(g2 ) Add a password to the user passwd      passwd username: Modify the password of the specified user only root passwd Modify your own password to delete the user: userdel -r: delete the user's home directory and modify the group groupmod           -n group_name: the new name            -g GID: the new GID     delete the group groupdel             groupdel GROUP group password: gpasswd -r [root@izm5e5qf7n47jhwufk5eo9z ~]# ls /home blair jerry tom ttt user1 user2 user3 user4 user7 wwwroot [root@izm5e5qf7n47jhwufk5eo9z ~]# userdel -r user3 [root@izm5e5qf7n47jhwufk5eo9z ~]# ls /home   



 










           







blair jerry tom ttt user1 user2 user4 user7 wwwroot file permissions      u owner  g belonging group o other permissions directory       r       w       x      file      r can use file viewing tools to get its content        w can modify its content       x can bring this file to the kernel to start as a Process Directory    r You can use ls to view the list of files in this directory        w You can create files in the directory again, or delete files in this directory        x You can use 1s -l to view the list of files in this directory You can cd into this directory    --- 000    - -x 001    Modify file permissions chmod                chmod  -R Recursively modify and modify directory permissions together with files    [root@izm5e5qf7n47jhwufk5eo9z ~]# touch /tmp/aaa.txt [root@izm5e5qf7n47jhwufk5eo9z ~]# ls /tmp/aaa.txt /tmp/aaa .TXT





 
 




      




 

   


   
   


   
    



           



[root@izm5e5qf7n47jhwufk5eo9z ~]# ls -l /tmp/aaa.txt
-rw-r--r-- 1 root root 0 Apr 14 14:27 /tmp/aaa.txt
[root@izm5e5qf7n47jhwufk5eo9z ~]# chmod 640 / tmp/aaa.txt
[root@izm5e5qf7n47jhwufk5eo9z ~]# ls -l /tmp/aaa.txt
-rw-r----- 1 root root 0 Apr 14 14:27 /tmp/aaa.txt [root@izm5e5qf7n47jhwufk5eo9z ~ ]# chmod u=rwx,g=r /tmp/aaa.txt [root@izm5e5qf7n47jhwufk5eo9z ~]# ls -l /tmp/aaa.txt -rwxr----- 1 root root 0 Apr 14 14:27 /tmp /aaa.txt Modify file owner chown       cchown [OPTION]... [OWNER][:[GROUP]] FILE...   -R Recursively modify        [root@izm5e5qf7n47jhwufk5eo9z ~]# chown tom:tom /tmp/aaa.txt    [root@izm5e5qf7n47jhwufk5eo9z ~]# ls -l /tmp/aaa.txt     -rwxr----- 1 tom tom 0 Apr 14 14:27 /tmp/aaa.txt 










  
  




Modify file group chgrp
     Usage: chgrp [OPTION]... GROUP FILE...
  or: chgrp [OPTION]... --reference=RFILE FILE...

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324422272&siteId=291194637