Linux useradd Create a new account, assign a group, change the group to which the user belongs, change the user to which the folder belongs, standardized management

Preface

1. Linux group permissions allow multiple users to share a set of permissions on objects in the system (such as files, directories, devices, etc.).
2. When creating a new user, adduserthe command will directly help us set a lot of information. useraddCombined with the command parameters, it can better help us set up the user, such as setting up user groups and logging in to the shell.
3. Sometimes we hope that the same group on the server can copy files to each other and can execute them, but cannot write them. That is, those in the same group can learn from each other, but you cannot modify mine randomly. For outsiders, it does not need to be open to others, or it can only be read or executed, so that administrators can better standardize management.

Create a new group name and create a new account

以管理员账户登入
1 新建组,group是你新建的组名。
sudo groupadd group
2. 新建用户,并且建立在我们刚建立的组下,yourname是你的用户名字。
sudo  useradd -g group -m  -s /bin/bash yourname
// useradd命令不会创建HOME目录, -m 可以使其创建HOME目录, -s 指定默认的登录shell, -g指定用户登录组的组名。
3.修改用户密码,不修改登不进去(也可以用 添加 -p xxx ,添加密码,但是会进行加密,导致密码并不是我们想设置的,不推荐,可通过修改密码,进行设置)
sudo passwd yourname

Change file ownership and change the user group to which the file belongs

1 更改文件的用户归属
//user为用户名,file_name为文件名字,若遍历文件夹,更改整个文件夹的归属,使用-R,dir_name为文件夹的名字。
sudo chown user  file_name
sudo chown user -R dir_name
2 改变文件所属用户组
// group为改变后的用户组,dir_name为需要改变组的文件夹名。
sudo chgrp group -R dir_name

Change permissions

// 关于权限问题可自行查阅相关知识,并根据自身需求设置,这里仅举个例子。
// 7代表文件属主的权限,有读取写入执行权限。5代表属组成员的权限,有读取和执行的权限。4代表其他账户的权限,仅有读的权限。dir_name为文件夹名字。
sudo chmod 754 -R dir_name

Guess you like

Origin blog.csdn.net/qq_44897728/article/details/112547670