Liunx basic commands (User Management)

Source: Internet
Author: User

Hello, this time I will introduce you to the management of users and user groups in liunx. You must know that the liunx system is basically a file, that is to say, users who want to translate the entire system can simply copy the relevant files. However, you need to pay attention to the introduction of users and user groups as well as how to create users manually. Come on ..



Last time it was easy to forget. But it is very important,


# Ait +. reference the last parameter of the previous command


Dynamic log monitoring is very important and will be used frequently in the future:

[Root @ 0425 ~] # Tail-f/var/log/messages


Make sure to copy the directory-r

[Root @ 0425 ~] # Cp-r/etc/a // root/


Create a directory file that does not exist:-p


[Root @ 0425 ~] # Mkdir/etc/aaa/

Mkdir: the directory "/etc/aaa/a" cannot be created: the file or directory does not exist.

[Root @ 0425 ~] # Mkdir-p/etc/aaa/

-----------------------------------------------------------------------


User Management:


[Root @ 0425 ~] # Id


Uid = 0 (root) gid = 0 (root) groups = 0 (root), 1 (bin), 2 (daemon), 3 (sys), 4 (adm ), 6 (disk), 10 (wheel)


Uid 0 root administrator) gid 0 Administrator Group)

Uid 1-499 system user) gid 1-499 system group)

Uid 500-60000 general user) gid500-60000 general user)



Additional group: for example, if you are in a relative's home, you cannot leave it as casual.


Different shell operations are not the same, but there is no limit on shell:


Set the user to a non-interactive shell

/Sbin/nologin: the user name and password flashed during login.


/Bin/bash common shell


---------------------------------------------

Update updegrip

Time upgrade) I cannot upgrade my system)

---------------------------------------------

User Files:

[Root @ 0425 bin] # vim/etc/passwd

User Group file:

[Root @ 0425 bin] # vim/etc/group

User Password File:

[Root @ 0425 bin] # vim/etc/shadow




Add User:

[Root @ 0425 ~] # Useradd abc1

The user system is in:

[Root @ 0425 ~] # Vim/etc/passwd


Passwd file content

Abc1: x: 915: 916:/home/abc1:/bin/bash

Username: Password placeholder: uid: gid: Description: Home Directory: shell

Name: Key: ID card number: house number: for example, I love my house at the door: Home Address: What do you say




Create a specified user:-u specify uid-g specify gid-c description-d home directory-s shell

When setting the Home Directory, do not add/to it to recognize the Directory)

[Root @ 0425 ~] # Useradd-u 915-g 916-c home-d/mnt/abc2-s/bin/bash abc1

--------------------

Add group: groupadd


Group files:

[Root @ 0425 ~] # Vim/etc/group



Abc1: x: 916:

Group Name: Password: gid: username with information

---------------------------

Set User Password:

[Root @ 0425 bin] # passwd abc2


-------------

When setting a password, a common user must conform to the complexity and length.

# Current) The current UNIX Password is

# New nuix passwd NEW Password

---------------

Store password files:

[Root @ 0425 bin] # vim/etc/shadow

----

Root: $1 $ Cdnpi781 $ CQWJ6dmljpPTbwO68Gy4A.: 15646: 0: 99999: 7 :::

Column 1: User Name

Column 2: Password

Column 3: last password modification time algorithm: the number of days since January 1, 1970)

Column 4: The minimum password time can be used in multiple days)

Column 5: Password Validity Period

Column 6: Quick Password Expiration warning time

Column 7: Account expiration time after Password Expiration

Column 8: account Validity Period

Column 9: reserved column

------------------

!! Lock password)

Mysql :!! : 15645 ::::::


* Logon password is permanently unavailable)

Ftp: *: 15643: 0: 99999: 7 :::


-------------


Modify group information: groupmod


[Root @ 0425 bin] # groupmod-g 1500 modify gid


[Root @ 0425 bin] # groupmod-n ttnew tt modify group name


[Root @ 0425 bin] # usermod-u-g-c-d-s modify user information


Usermod-f account expiration time after password expiration-e account Validity Period

Usermod-l New Name Change User Name

Usermod-L lock account

Usermod-U unlock account


Note the following when modifying the home directory:


[Root @ 0425 dev] # useradd 444 create a user 444

[Root @ 0425 dev] # Change usermod-d/mnt/444 444 from home directory to mnt directory

[Root @ 0425 mnt] # su 444

Bash-3.2 $ no home directory !!!


The following directory must be in mv/home/444/mnt /.

If you create a 444 folder directly under mnt, you still do not need to recognize it by cp/etc/skel/. bash */mnt/444.



Change password information:

Main directory:

[Root @ 0425 bin] # vim/etc/shadow


Passwd-n minimum time

Passwd-x maximum time

Passwd-w warning time

Passwd-I password expiration time

Passwd-l lock User Password

Passwd-u unlock Password

Passwd-S to view the password status


Delete user information:


Groupdel group name delete user group

Userdel-r user name deletion user deleted together with home directory



About the user's main configuration file;

[Root @ 0425 bin] # vim/etc/default/useradd


1 # useradd defaults file

2 GROUP = 100

3 HOME =/home default HOME directory

4 INACTIVE =-1-1 permanent

5 EXPIRE = Account Validity Period

6 SHELL =/bin/bash the default shell is

7 SKEL =/etc/skel

8 CREATE_MAIL_SPOOL = yes: is an email/var/spool/mail created when a user is created)

Home =/home

Shell =/bin/bash

CREATE_MAIL_SPOOL = yes



Default password information:


/Etc/login. defs



------------------------------------------------------------------


Additional group:


[Root @ 0425 mnt] # groupadd kf

[Root @ 0425 mnt] # groupadd yw

[Root @ 0425 mnt] # useradd-G kf, yw wg add additional group

[Root @ 0425 mnt] # usermod-a-G boss abc1 add an additional group boss to the abc1 Group



[Root @ 0425 mnt] # su wg

[Root @ 0425 mnt] # sg yw



[Root @ 0425 mnt] # groupadd boss

[Root @ 0425 mnt] # gpasswd boss

Modifying the password of the boss Group

New password:

Enter the new password again:


[Root @ 0425 ~] # Id

Uid = 0 (root) gid = 0 (root) groups = 0 (root), 1 (bin), 2 (daemon), 3 (sys), 4 (adm ), 6 (disk), 10 (wheel)

[Root @ 0425 ~] # Sg boss

[Root @ 0425 ~] # Id

Uid = 0 (root) gid = 505 (boss) groups = 0 (root), 1 (bin), 2 (daemon), 3 (sys), 4 (adm ), 6 (disk), 10 (wheel), 505 (boss)

[Root @ 0425 ~] # Sg kf

[Root @ 0425 ~] # Id

Uid = 0 (root) gid = 502 (kf) groups = 0 (root), 1 (bin), 2 (daemon), 3 (sys), 4 (adm ), 6 (disk), 10 (wheel), 502 (kf), 505 (boss)

[Root @ 0425 ~] # Sg yw

[Root @ 0425 ~] # Id

Uid = 0 (root) gid = 503 (yw) groups = 0 (root), 1 (bin), 2 (daemon), 3 (sys), 4 (adm ), 6 (disk), 10 (wheel), 502 (kf), 503 (yw), 505 (boss)

[Wg @ 0425 ~] $ Sg boss

Password:

[Wg @ 0425 ~] $ Id

Uid = 500 (wg) gid = 505 (boss) groups = 500 (wg), 502 (kf), 503 (yw), 505 (boss)

[Wg @ 0425 ~] $ Su-wg

Password:

Su: incorrect password


[Wg @ 0425 ~] $ Sg kf

[Wg @ 0425 ~] $ Id

Uid = 500 (wg) gid = 502 (kf) groups = 500 (wg), 502 (kf), 503 (yw), 505 (boss)

[Wg @ 0425 ~] $ Sg boss

Password:


[Wg @ 0425 ~] $ Sg yw

[Wg @ 0425 ~] $ Id

Uid = 500 (wg) gid = 503 (yw) groups = 500 (wg), 502 (kf), 503 (yw), 505 (boss)

[Wg @ 0425 ~] $ Sg boss

Password:





Password File of the group:


[Root @ 0425 bin] # vim/etc/gshadow


[Root @ 0425 mnt] # useradd-u 0-o admin users who add duplicate uid)



Manually Manage Users:

# Groupadd redhat


Vim/etc/group

Redhat: x: 5000:



# Useradd eric


Vim/etc/passwd

Eric: x: 5000: 5000: PT:/home/eric:/bin/bash (this shell says/sbin/bash) cause: eirc is a common user. It is not an administrator user and cannot see sbin commands.


Mkdir/home/eric


Configuration File Environment Variables

Cp/etc/skel/. bash */home/eric/


# Passwd eric


Vim/etc/shadow

Eric :!! : 15654: 0: 99999: 7 :::


Md5 password generation

Grub-md5-crypt


----------------------------------------------------

Import from all users on a computer to make a computer


Multi-user import


Touch user.txt

Aa: x: 5500: 5500:/home/aa:/bin/bash

Bb: x: 5600: 5600:/home/bb:/bin/bash



Newusers <user.txt import account user

Caoni: 123: 15649: 0: 99999: 7 :::


Touch passwd.txt

Aa: 123

Bb: 123.



Chpasswd <passwd.txt import Password


Configuration File Environment Variables

Cp/etc/skel/. bash */home/aa/

Cp/etc/skel/. bash */home/bb/



-------------------------------

Roles of files in the Home Directory

. Bash_history records historical user execution files



. Bash_logout Command executed when the user exits



. Bashrc environment variable nologin-shell can take effect level environment configuration file without logon


. Bash_profile environment variable login-shell must be logged on to take effect login level environment Configuration



[Root @ 0425/] #/etc/bashrc set the environment variables of all the shells.

[Root @ 0425/] #/etc/profile: Set the environment variable logon for all shells.


Loading Sequence

/Etc/profile

~ /. Bash_profile

~ /. Bashrc

/Etc/bashrc




Custom variables:

[Root @ 0425/] # a = 1

[Root @ 0425/] # echo $

1


Current variable:

[Root @ 0425/] # a = 10

[Root @ 0425/] # echo $

10

[Root @ 0425/] # bash

[Root @ 0425/] # echo $


The current variable can be executed in the current shell but not in the subshell.



Environment variable:

Aaa = 1111111111111111111111 set the aaa variable to 11111111111

Set global variables for export aaa

Echo $ aaa $ (retrieve variable) check that the aaa value of the retrieved variable is 111111111111

11111111111111111111


It can be in the current shell or in the sub-shell.


View variables:

Env

Echo $ SHELL



When switching a user: If su-aa is not added, the user may not be able to find the Administrator command. The environment variable remains unchanged.



This article is from the "history_xcy" blog, please be sure to keep this http://historys.blog.51cto.com/7903899/1296614

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.