0

I am aware that a new user's home directory can be created by doing sudo useradd -m -d /home/<username> <username>.

However, let's say that I also want to make another non-home directory for this user at /ssd/<username>, and I do not want to make it by hand each time I add a new user to the system. In other words, I do not want to do these separately:

  • useradd -m -d /home/<username> <username>
  • mkdir /ssd/<username>
  • change the directory permissions.

I would like to do all 3 in a single command.

Does useradd or adduser provide an option that can do this at the creation time of the user?

5Pack
  • 101
  • 2
    Why not write a shell script that does the `useradd`/`adduser` followed by the `mkdir` (and optionally `chown` and/or `chmod`)? – Jeff Zeitlin Jan 24 '23 at 15:26
  • @JeffZeitlin I wanted to know if there was already a way built into those commands before trying to write my own script. You don't believe there is a built-in method already? – 5Pack Jan 24 '23 at 18:58
  • I do not; utilities in *IX, dating back at least to UNIX System III, seem to have the philosophy of "don't do much, but what you do do, do well", and "string together lots of pieces that do standard tasks to do a custom job". My first inclination would, in fact, be to slap together a shell script if `man adduser` didn't give me an immediately obvious answer. – Jeff Zeitlin Jan 24 '23 at 19:02
  • For what it's worth, I did much the same thing in DOSBatch/WinBatch and do now in PowerShell on Windows. – Jeff Zeitlin Jan 24 '23 at 19:03

1 Answers1

0

In /etc/login.defs there may be an entry - USERADD_CMD /usr/sbin/useradd.local. This is run after useradd. Edit the /usr/sbin/useradd.local file to create whatever you want and if required change the permissions..

Bib
  • 1,175
  • 1
  • 6
  • 8