useradd utility uses a number of default values when creating a new user. One of those defaults is a skeleton directory, which is used as a base for user's home directories.
The skeleton directory is configured inside
You can add the
config.sh file to this directory so that it is automatically added for all new users as part of their home directory.
Example: Let's create a simple script file named
[root@testvm ~]# cat config.sh
echo "Hello World!"
We'll give the script execute permissions:
[root@testvm ~]# chmod +x config.sh
Next, we copy the script over to the skeleton directory,
[root@testvm ~]# cp -a ~/config.sh /etc/skel/
Now, let's add the new user*:
[root@testvm ~]# useradd -c "New User" -md /home/NU -e 2018-12-20 -s /bin/bash -u 2000 newuser
Finally, we'll switch to the new user and verify that the file has been placed in the user's home directory:
[root@testvm ~]# su - newuser
[newuser@testvm ~]$ ls -l
-rwxr-xr-x. 1 newuser newuser 32 Dec 1 22:08 config.sh
[newuser@testvm ~]$ ./config.sh
*I have modified the
useradd command from the question. The username has to be specified last, after all the options, and the expiry date uses the YYYY-MM-DD format.