Linux中修改用户UID和组GID的方法

···
[root@weblog u01]# id oracle
uid=1000(oracle) gid=1000(oinstall) groups=1000(oinstall),1001(dba)
[root@weblog u01]# usermod -u 1002 oracle
[root@weblog u01]# id oracle
uid=1002(oracle) gid=1000(oinstall) groups=1000(oinstall),1001(dba)
[root@weblog u01]# groupmod -g 1100 dba
[root@weblog u01]# id oracle
uid=1002(oracle) gid=1000(oinstall) groups=1000(oinstall),1100(dba)
···
但是oracle用户的家目录下面的文件属主和属组会在1、2命令执行后自动修改成新的uid、gid对应的属主属组,但是其他文件目录需要手动修改。手动修改的命令也比较简单。
注意:更改完uid、gid后,目录的属组也需要修改

[root@weblog /]# ll
total 28
lrwxrwxrwx.   1 root root        7 Dec 17 10:33 bin -> usr/bin
dr-xr-xr-x.   5 root root     4096 Dec 17 11:01 boot
drwxr-xr-x   20 root root     3420 Dec 17 11:04 dev
drwxr-xr-x. 145 root root     8192 Dec 17 13:51 etc
drwxr-xr-x.   3 root root       28 Dec 17 13:44 home
lrwxrwxrwx.   1 root root        7 Dec 17 10:33 lib -> usr/lib
lrwxrwxrwx.   1 root root        9 Dec 17 10:33 lib64 -> usr/lib64
drwxr-xr-x.   2 root root        6 Apr 11  2018 media
drwxr-xr-x.   2 root root        6 Apr 11  2018 mnt
drwxr-xr-x.   3 root root       16 Dec 17 10:38 opt
dr-xr-xr-x  417 root root        0 Dec 17 11:04 proc
dr-xr-x---.   7 root root     4096 Dec 17 13:39 root
drwxr-xr-x   41 root root     1180 Dec 17 11:04 run
lrwxrwxrwx.   1 root root        8 Dec 17 10:33 sbin -> usr/sbin
drwxr-xr-x.   2 root root        6 Apr 11  2018 srv
dr-xr-xr-x   13 root root        0 Dec 17 13:54 sys
drwxrwxrwt.  13 root root     4096 Dec 17 13:44 tmp
drwxr-xr-x    3 1000 oinstall  207 Dec 17 13:48 u01
drwxr-xr-x.  13 root root      207 Dec 17 10:33 usr
drwxr-xr-x.  21 root root     4096 Dec 17 10:45 var

可以看到u01的拥有者变成了1000:

drwxr-xr-x    3 1000 oinstall  207 Dec 17 13:48 u01

修改后变回oracle

[root@weblog /]# chown -R oracle:oinstall /u01
[root@weblog /]# ll
total 28
lrwxrwxrwx.   1 root   root        7 Dec 17 10:33 bin -> usr/bin
dr-xr-xr-x.   5 root   root     4096 Dec 17 11:01 boot
drwxr-xr-x   20 root   root     3420 Dec 17 11:04 dev
drwxr-xr-x. 145 root   root     8192 Dec 17 13:51 etc
drwxr-xr-x.   3 root   root       28 Dec 17 13:44 home
lrwxrwxrwx.   1 root   root        7 Dec 17 10:33 lib -> usr/lib
lrwxrwxrwx.   1 root   root        9 Dec 17 10:33 lib64 -> usr/lib64
drwxr-xr-x.   2 root   root        6 Apr 11  2018 media
drwxr-xr-x.   2 root   root        6 Apr 11  2018 mnt
drwxr-xr-x.   3 root   root       16 Dec 17 10:38 opt
dr-xr-xr-x  417 root   root        0 Dec 17 11:04 proc
dr-xr-x---.   7 root   root     4096 Dec 17 13:39 root
drwxr-xr-x   41 root   root     1180 Dec 17 11:04 run
lrwxrwxrwx.   1 root   root        8 Dec 17 10:33 sbin -> usr/sbin
drwxr-xr-x.   2 root   root        6 Apr 11  2018 srv
dr-xr-xr-x   13 root   root        0 Dec 17 13:54 sys
drwxrwxrwt.  13 root   root     4096 Dec 17 13:44 tmp
drwxr-xr-x    3 oracle oinstall  207 Dec 17 13:48 u01
drwxr-xr-x.  13 root   root      207 Dec 17 10:33 usr
drwxr-xr-x.  21 root   root     4096 Dec 17 10:45 var

你可能感兴趣的:(笔记,Linux,Oracle)