Find the answer to your Linux question:
Results 1 to 8 of 8
I know that when we already have a folder example /home/ABC and if we want to assign this folder to the new user ad a home directory then we run ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2012
    Posts
    19

    difference between useradd -d and useradd -b


    I know that when we already have a folder example /home/ABC and if we want to assign this folder to the new user ad a home directory then we run the command useradd -d /home/ABC username
    But I dont able to understand what -b switch does ?

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    The -b switch tells useradd to use whatever dir you specify (after the -b) as the base home dir, instead of the default (typically "/home"). so if you do:
    Code:
    useradd -b /tmp -g users tmpuser
    it will create user "tmpuser" with a home dir of /tmp/tmpuser.

    if you were to use the -d switch simultaneously, it would override whatever the base home dir is, whether you've used -b or not.

    run man useradd for more details.

  3. #3
    Just Joined!
    Join Date
    Feb 2012
    Posts
    19
    Thanks for your kind reply. I understood

    Last question : Does the -d switch try to transfer any file from /etc/skel directory ? or -d switch just tell to useradd command that dont create the home directory and use the mentioned directory path with the d switch as the home directory.

  4. $spacer_open
    $spacer_close
  5. #4
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by zahidhaseeb View Post
    Last question : Does the -d switch try to transfer any file from /etc/skel directory ? or -d switch just tell to useradd command that dont create the home directory and use the mentioned directory path with the d switch as the home directory.
    yes, the -d switch just changes where the user's homepath will be, it won't disable the copying of SKEL files.

  6. #5
    Just Joined!
    Join Date
    Feb 2012
    Posts
    19
    thanks for reply

    Quote Originally Posted by atreyu View Post
    it won't disable the copying of SKEL files.

    I tried the below:
    # useradd -d /home/arif/ arif
    useradd: warning: the home directory already exists.
    Not copying any file from skel directory into it.

    The warning means that home directory already created thats why the skel is no going to copy the files to it
    Last edited by zahidhaseeb; 07-12-2012 at 02:06 PM.

  7. #6
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by zahidhaseeb View Post
    I tried the below:
    # useradd -d /home/arif/ arif
    useradd: warning: the home directory already exists.
    Not copying any file from skel directory into it.

    The warning means that home directory already created thats why the skel is no going to copy the files to it
    ah, i see why there is a discrepancy: i was running my useradd commands on a RHEL 4 box. I just tried it on a Fedora 17 box and I now get the "Not copying any file from skel" error, too. so clearly something changed w/the newer version of useradd.

    if you need the contents of the skel dir added to a new user's home dir (and that home dir already exists), i guess you can just add a line in your user creation script to copy the skel stuff over - something like:

    Code:
    rsync -av /etc/skel/ /home/<USER>/ && chown -R <USER>:<GROUP> /home/<USER>/

  8. #7
    Just Joined!
    Join Date
    Feb 2012
    Posts
    19
    Thanks atreyu . I just wanted to confirm that the skel files will not be copied in to the already created home directory when we run the useradd command as I had a scare that my already exist files may not be overwritten.

    New RHEL6.2 may feel that if the home directory is already created then the skel files may also be there so copying the skel files again may overwrite the already exist skel files and these already exist files may have modified data. So I think new RHEL6.2 is not copying the skel files as the Warning message shows..

    Thanks atreyu again for your kind comments

  9. #8
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by zahidhaseeb View Post
    Thanks atreyu . I just wanted to confirm that the skel files will not be copied in to the already created home directory when we run the useradd command as I had a scare that my already exist files may not be overwritten.
    if that was your concern, you could always use the -k option, pointing to an empty "skel" directory. but it sounds like you are good to go.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •