安装Oracle,新建组、用户的时候的一个错误

[root@localhost /]# mkdir -p /u01/oracle
[root@localhost /]# useradd -g oinstall -G dba -d /u01/oracle/ oracle
useradd: warning: the home directory already exists.
Not copying any file from skel directory into it.
而且/u01/oracle目录下没有任何文件。
 
解决方法:
 
网上查了一下,方法各式各样。我觉得这个方法还是简单些。
不要手动建oracle目录。
[root@localhost /]# mkdir /u01
[root@localhost ~]# useradd -g oinstall -G dba -d /u01/oracle oracle
Creating mailbox file: File exists
[root@localhost ~]# ll -a /u01/oracle/
total 32
drwx------. 4 oracle oinstall 4096 Aug 10 19:41 .
drwxr-xr-x. 3 oracle oinstall 4096 Aug 10 19:41 ..
-rw-r--r--. 1 oracle oinstall   18 May 30 12:58 .bash_logout
-rw-r--r--. 1 oracle oinstall  176 May 30 12:58 .bash_profile
-rw-r--r--. 1 oracle oinstall  124 May 30 12:58 .bashrc
-rw-r--r--. 1 oracle oinstall  500 Jan 23  2007 .emacs
drwxr-xr-x. 2 oracle oinstall 4096 Nov 11  2010 .gnome2
drwxr-xr-x. 4 oracle oinstall 4096 Aug 10 17:32 .mozilla
 
原因:
 
系统添加用户的标准步骤
1.编辑/etc/passwd与/etc/group
2.创建用户主目录
3.从/etc/skel拷贝文件与目录
4.让新用户获得其主目录与文件的拥有权限
5.给新用户一个密码
 
查useradd代码:
static void create_home (void)
{
    if (access (user_home, F_OK) != 0) {
#ifdef WITH_SELINUX
        selinux_file_context (user_home);
#endif
        /* XXX - create missing parent directories. --marekm */
        if (mkdir (user_home, 0) != 0) {
            fprintf (stderr,
             _("%s: cannot create directory %s\n"),
             Prog, user_home);
#ifdef WITH_AUDIT
            audit_logger (AUDIT_ADD_USER, Prog,
             "adding home directory",
             user_name, (unsigned int) user_id,
             SHADOW_AUDIT_FAILURE);
#endif
            fail_exit (E_HOMEDIR);
        }
        chown (user_home, user_id, user_gid);
        chmod (user_home,
         0777 & ~getdef_num ("UMASK", GETDEF_DEFAULT_UMASK));
        home_added = true;
#ifdef WITH_AUDIT
        audit_logger (AUDIT_ADD_USER, Prog,
         "adding home directory",
         user_name, (unsigned int) user_id,
         SHADOW_AUDIT_SUCCESS);
#endif
#ifdef WITH_SELINUX
        /* Reset SELinux to create files with default contexts */
        setfscreatecon (NULL);
#endif
    }
}

int main(int argc, char *argv[])
{
              ................
                create_home ();
                if (home_added)
                        copy_tree (def_template, user_home, user_id, user_gid);
                else
                        fprintf (stderr,
                                 _
                                 ("%s: warning: the home directory already exists.\n"
                                  "Not copying any file from skel directory into it.\n"),
                                 Prog);

                 ......................
             }
View Code

前先不建/u01/oracle,  报错 是因为        if (mkdir (user_home, 0)) { 相当于没有参数  -p 的mkdir /u01/oracle
建了/u01/oracle 有useradd:警告:此主目录已经存在。
不从 skel 目录里向其中复制任何文件 是因为 if (access (user_home, F_OK)) { 这个 /u01/oracle目录已经存在
所以只有只指定不含子路径的时候才能没有警告出现

 
结合代码可以看到网上找到另个解决方法是:
依旧使用上面的脚本建用户,然后手动拷贝配置文件到/u01/oracle下。
cp /etc/skel/.bash_profile     /u01/oracle
cp /etc/skel/.bashrc     /u01/oracle
cp /etc/skel/.bash_logout     /u01/oracle

 

这样既可。

posted @ 2015-04-27 10:28  stemon  阅读(1218)  评论(0编辑  收藏  举报