linux用户组权限

linux用户组权限

1) 创建用户组

sudo groupadd testGroup

2) 创建新的用户账号mysql

sudo useradd -g testGroup -d /home/mysql -m mysql

2) 给用户mysql设置密码, 然后输入两次密码确认

sudo passwd mysql

useradd命令:

Usage: useradd [options] LOGIN

Options:
  -b, --base-dir BASE_DIR       base directory for the home directory of the
                                new account
  -c, --comment COMMENT         GECOS field of the new account
  -d, --home-dir HOME_DIR       home directory of the new account
  -D, --defaults                print or change default useradd configuration
  -e, --expiredate EXPIRE_DATE  expiration date of the new account
  -f, --inactive INACTIVE       password inactivity period of the new account
  -g, --gid GROUP               name or ID of the primary group of the new
                                account
  -G, --groups GROUPS           list of supplementary groups of the new
                                account
  -h, --help                    display this help message and exit
  -k, --skel SKEL_DIR           use this alternative skeleton directory
  -K, --key KEY=VALUE           override /etc/login.defs defaults
  -l, --no-log-init             do not add the user to the lastlog and
                                faillog databases
  -m, --create-home             create the user's home directory
  -M, --no-create-home          do not create the user's home directory
  -N, --no-user-group           do not create a group with the same name as
                                the user
  -o, --non-unique              allow to create users with duplicate
                                (non-unique) UID
  -p, --password PASSWORD       encrypted password of the new account
  -r, --system                  create a system account
  -s, --shell SHELL             login shell of the new account
  -u, --uid UID                 user ID of the new account
  -U, --user-group              create a group with the same name as the user
  -Z, --selinux-user SEUSER     use a specific SEUSER for the SELinux user mapping
Linux用户组权限管理是Linux系统安全管理的重要组成部分。通过对用户进行分组,并赋予不同的权限,可以有效地控制用户对系统资源的访问。以下是一些常见的用户组权限管理方法: 1. **创建用户组**: 使用`groupadd`命令可以创建一个新的用户组。例如,创建一个名为`developers`的用户组: ```bash sudo groupadd developers ``` 2. **将用户添加到用户组**: 使用`usermod`命令可以将用户添加到指定的用户组。例如,将用户`john`添加到`developers`组: ```bash sudo usermod -aG developers john ``` 3. **查看用户所属的用户组**: 使用`groups`命令可以查看用户所属的用户组。例如,查看用户`john`所属的用户组: ```bash groups john ``` 4. **设置文件或目录的权限**: 使用`chmod`命令可以设置文件或目录的权限。例如,将`/var/www/html`目录的权限设置为`755`,即所有者有读、写、执行权限,所属组和其他用户有读、执行权限: ```bash sudo chmod 755 /var/www/html ``` 5. **更改文件或目录的所有者和所属组**: 使用`chown`命令可以更改文件或目录的所有者和所属组。例如,将`/var/www/html`目录的所有者更改为`root`,所属组更改为`developers`: ```bash sudo chown root:developers /var/www/html ``` 6. **查看文件的权限**: 使用`ls -l`命令可以查看文件的权限。例如,查看`/var/www/html/index.html`的权限: ```bash ls -l /var/www/html/index.html ``` 通过这些方法,可以有效地管理Linux系统中的用户组权限,确保系统的安全性和资源的合理分配。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值