创建5个组,然后把30个用户分别加入到5个组中
Readme:设计一个shell程序,添加一个新组为groupX,然后添加属于这个组的30个用户,用户名的形式为groupX_userYY,其中x从01到10,YY从01到30。
#!/bin/bash for i in $(seq 1 10);do g="group$i" groupadd $g for ii in $(seq 1 30);do u="${g}_user$ii" useradd $u -g $g done done
创建新用户
创建一个用户名为:user01
[root@localhost ~]# adduser user01
为这个用户初始化密码,linux会判断密码复杂度,不过可以强行忽略:
[root@localhost ~]# passwd user01
授权
个人用户的权限只可以在本home下有完整权限,其他目录要看别人授权。而经常需要root用户的权限,这时候sudo可以化身为root来操作。我记得我曾经sudo创建了文件,然后发现自己并没有读写权限,因为查看权限是root创建的。
新创建的用户并不能使用sudo命令,需要给他添加授权。
sudo命令的授权管理是在sudoers文件里的。可以看看sudoers:
root@localhost ~]# sudoers bash: sudoers: 未找到命令... [root@localhost ~]# whereis sudoers sudoers: /etc/sudoers /etc/sudoers.d /usr/libexec/sudoers.so /usr/share/man/man5/sudoers.5.gz
找到这个文件位置之后再查看权限:
[root@localhost ~]# ls -l /etc/sudoers -r--r----- 1 root root 4251 7月 25 15:08 /etc/sudoers
是的,只有只读的权限,如果想要修改的话,需要先添加w权限:
[root@localhost ~]# chmod -v u+w /etc/sudoers mode of "/etc/sudoers" changed from 0440 (r--r-----) to 0640 (rw-r-----)
然后就可以添加内容了,在下面的一行下追加新增的用户:
[root@localhost ~]# vim /etc/sudoers ## Allow root to run any commands anywher root ALL=(ALL) ALL user01 ALL=(ALL) ALL #这个是新增的用户
wq保存退出,这时候要记得将写权限收回:
[root@localhost ~]# chmod -v u-w /etc/sudoers mode of "/etc/sudoers" changed from 0640 (rw-r-----) to 0440 (r--r-----)
这时候使用新用户登录,使用sudo:
[linuxidc@localhost ~]$ sudo cat /etc/passwd [sudo] password for user01: We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things: #1) Respect the privacy of others. #2) Think before you type. #3) With great power comes great responsibility.
第一次使用会提示你,你已经化身超人,身负责任。而且需要输入密码才可以下一步。如果不想需要输入密码怎么办,将最后一个
ALL
修改成NOPASSWD: ALL
。
首次对一个表空间分配用户,比如表空间为A,用户为USER01,赋予该用户dba权限,之后想在新建一个只有查询权限的用户USER02,做法如下:使用USER01用户创建一个新用户USER02,只赋予CONNECT权限。使用该用户查询语句为SELECT * from A.TAB; 其中tab为表空间A的某个表名。如果使用用户USER01只需这样查询SELECT * from TAB;
创建5个组,然后把30个用户分别加入到5个组中
Readme:设计一个shell程序,添加一个新组为groupX,然后添加属于这个组的30个用户,用户名的形式为groupX_userYY,其中x从01到10,YY从01到30。
#!/bin/bash for i in $(seq 1 10);do g="group$i" groupadd $g for ii in $(seq 1 30);do u="${g}_user$ii" useradd $u -g $g done done
转载于:https://www.cnblogs.com/tangshengwei/p/5520434.html
创建一个新用户
CREATE USER 'test'@'127.0.0.1' IDENTIFIED BY '123456';
给用户增加访问数据库权限 test表示数据库 *表示数据库表 为星表示所有
GRANT ALL PRIVILEGES ON data.* TO 'test'@'127.0.01';
外网访问下的表权限 %表示所有权限 如,增删改等
grant all privileges on data.* to 'test'@'%' identified by '123456';
允许外网访问
create user 'test'@'%' identified by '123456';
完成要为新用户设置的权限后,请务必重新加载所有权限。
FLUSH PRIVILEGES;