Linux system shutdown / reboot / User Switching / logout, user management (user to create / modify user group add / remove), except the Linux / ~ and the

1. shutdown / restart command

shutdown command 
    shutdown - H now: shutdown immediate 
    shutdown -h 1    : 1 minute shutdown 
    shutdown - r now: immediately restart 
    shutdown -r 1    : 1 minutes after the restart halt 
    shutdown reboot 
    reboot sync 
    to synchronize data memory to disk



Special Note: the current shutdown or restart, you should first look sync command execution, the memory data is written to disk to prevent data loss

2. The user switches / logout

Basic instructions:

Normal in the company will not give you root privileges, even if you root privileges, and do not bring the root user to log, to avoid operational errors. Normally it is a regular user login, and then the main administrator privileges when then switch.

Switch User

su - username switch user 
exit back to the original user

Logout

Premise: the graphical interface invalid 
logout

3. User Management

1 . Linux system is a multi-user multi-tasking operating system, a user want to use any system resources, must first apply for an account to the system administrator, and then log in as the account. 

2.Linux user needs to belong to at least one group

1. Add user

useradd [options] user name
 
example: useradd LXX     (create user lxx)
Description:

automatically creates and names the same name as the user's home directory 1. Create a user after successful

Creating a user eee, will also create a directory of user names with the same name in the user's home directory / home

Specifies the home directory to create a user 
useradd - d directory path to the user name     (Note: When creating a user, the directory path does not already exist)

 to specify a user group to create a user 
useradd -g group user name user name      (Note: When creating a user, user group name must exist )

2. Give the user to specify or change passwords

Above but did not create a user to create a password, can not log on without a password at login

grammar:

passwd username

3. Delete user

The basic syntax

Delete user userdel username, leave home directory 
userdel -r username to delete a user, do not retain home directory

Description: Normally we delete the user, the general will remain the home directory

4. Query User Information

The basic syntax

id username

refers uid user id, GID refers to the group id, the name of the latter group is the group

Username does not exist

5. Switch user

When the user access is not enough, by su -, the user to switch to a high authority, such as the root user

The basic syntax

su - 用户名        切换用户
exit              返回原来用户

补充说明:从高权限用户切换到低权限用户时,不需要密码

当root用户切换到eee时不需要密码,当eee切换到root时需要填root用户的密码

 

小练习:
1.创建一个lxx的用户并指定密码
    useradd lxx
    passwd lxx
2.切换到lxx
    su - lxx
3.尝试cd到/root目录
    权限不够
4.切换回root用户
    su -root 输入密码
    exit或者logout
5.再次cd到/root目录
   cd /root

6.用户组

说明:

用以对具备同一权限的用户进行统一管理,就好比:运维组,技术组

1.增加组

groupadd 组名

2.删除组

groupdel 组名

前提:组内不能有用户,否则无法删除

创建用户时候添加组(前提是有这个组)

useradd -g 组名 用户名

例子:

useradd -g renyao lxx     (把用户lxx加入renyao组)

7.修改用户的组

基本指令

usermod -g 组名 用户名   (用户组修改用户)  注意:组名一定要存在

8./etc/passwd 文件

这是用户的配置文件,记录着用户的各种信息

  /  目录下 运行

vim /etc/passwd

在最下面显示刚才创建的几个新用户

每行含义   用户名:口令(不显示):用户id:组id:注释性描述:主目录:Shell

9./etc/shadow文件

基本语法

vim /etc/shadow

口令配置文件,存用户密码和相关时间的地方

10./etc/group 文件

组的配置文件

 

Linux中  /  和 ~ 的区别

~ 是当前用户的目录地址

/   是根目录的地址(一般称呼为root,/ 和 /root/ 是有区别的)
/ 也指目录分隔符 ~是一个代位符号表明个人目录的地址 ,因为每个用户都有自己的个人目录地址,所以同意用~替代这个,根据用户不同而不同,但有规可循的地址,来保证某些情况下的兼容问题。
一、 当用户是root用户时

     ~  代表/root/,即根目录下的root目录

     /    代表/ ,即根目录

二、当用户是普通用户user时

      ~  代表/home/user,即根目录下的home目录下的user目录

      /    代表/ ,即根目录

Guess you like

Origin www.cnblogs.com/wangcuican/p/12057321.html