Forum › Forums › New users › New Users and General Questions › How to script the creation of a new user?
- This topic has 3 replies, 3 voices, and was last updated May 7-1:06 pm by Keeely.
-
AuthorPosts
-
May 6, 2021 at 10:10 am #58717Member
Keeely
I have created a new user on the live system of Core, using the following command:
useradd -m -g users bob -s /bin/bashHowever after running the cli-installer I end up with these permissions on that /home directory:
# ls -l /home total 4 drwxr-xr-x 4 1000 1000 4096 May 6 05:29 bobBut I would expect to see:
drwxr-xr-x 4 bob users 4096 May 6 05:29 bobAfter I manually correct that with:
chown -R bob:users /home/bobssh then starts working correctly.
Just wondering am I creating the user wrong?
thanks!
May 6, 2021 at 10:48 am #58720Member
Xecure
::Did you try?
sudo useradd -m -g users -s /bin/bash bob
If I am not mistaken, useradd has this structure
useradd [OPTIONS] username
So the username needs to go at the end.antiX Live system enthusiast.
General Live Boot Parameters for antiX.May 7, 2021 at 5:43 am #58794Anonymous
::Just wondering
am I creating the user wrongis there a better way?The “adduser” command is usually preferable over useradd,
and “adduser bob” (without typing further commandline options) should yield a desirable result.For more info, you can “man login.defs” and “man adduser” and “sudo cat /etc/login.defs”
$ sudo adduser spooky3 Adding user 'spooky3' ... Adding new group 'spooky3' (1003) ... Adding new user 'spooky3' (1003) with group 'spooky3' ... Creating home directory '/home/spooky3' ... Copying files from '/etc/skel' ... New password: Retype new password: passwd: password updated successfully Changing the user information for spooky3 Enter the new value, or press ENTER for the default Full Name []: Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n] Adding new user 'spooky3' to extra groups ... Adding user 'spooky3' to group 'dialout' ... Adding user 'spooky3' to group 'dip' ... adduser: The group 'fuse' does not exist. Adding user 'spooky3' to group 'cdrom' ... Adding user 'spooky3' to group 'audio' ... Adding user 'spooky3' to group 'video' ... Adding user 'spooky3' to group 'plugdev' ... Adding user 'spooky3' to group 'users' ... Adding user 'spooky3' to group 'floppy' ... Adding user 'spooky3' to group 'netdev' ... Adding user 'spooky3' to group 'scanner' ... Adding user 'spooky3' to group 'lp' ... Adding user 'spooky3' to group 'lpadmin' ... Adding user 'spooky3' to group 'sudo' ... Adding user 'spooky3' to group 'vboxsf' ...May 7, 2021 at 1:06 pm #58806MemberKeeely
::I think the operations with the demo account in cli-installer could interfere with the created account somehow, because everything is fine in the live system, but it gets messed up after the install (under /media), and those demo account operations are the only time groups and users are touched as part of the installer. That’s just a theory, I don’t have proof, but there’s some stuff in that area of cli-installer that looks a little iffy.
I decided to try to add the default user as part of cli-installer instead of doing it independently before running cli-install. (make that my main account, but not auto-login). Then everything works OK. There is one small problem with this approach if you are automating cli-installer. An answerfile works perfectly OK when you set the root password (primary account as root), but when you set the primary account to be something else, it didn’t work.
I needed to write a proper expect script when I include that extra part of cli-installer in the flow, it’s as if the password setting for non-root user uses the tty in a different way to just setting the root pw, and it goes completely nuts spewing out password errors with simple answerfile piped to stdin.
Anyways, it’s all fixed now, and I only need one account so setting it up in cli-installer works OK for me.
In case this is useful for anyone else, full script is:
/usr/bin/expect << ENDOFCLIINSTALLERSCRIPT spawn cli-installer expect "Do you want to repartition the disk (y/N)? " send "n\n" expect "Root partition (hda1, sda2, etc): " send "sda1\n" expect "Do you want to continue (No will abort the installation) (n/Y)? " send "y\n" expect "Do you want to use a separate '/home' partition (y/N)? " send "n\n" expect "Are you running antiX-net (y/N)? " send "n\n" expect "Do you want to install some packages via cli-aptiX (y/N)? " send "n\n" expect "Do you want to continue (No will abort the install) (n/Y)? " send "y\n" expect "This may take some time." set timeout 120 expect "Install GRUB on MBR (Y/n) No will install to root partition? " send "y\n" set timeout 30 expect "Computer name (default is 'antix1')? " send "\n" expect "Do you want to set up system localisation (y/N)? " send "n\n" expect "Do you want to set up keyboard (y/N)? " send "n\n" expect "Do you want to set up console layout (y/N)? " send "n\n" expect "Do you want to set up system timezone (y/N)? " send "n\n" expect "Do you want to enable/disable startup services (y/N)? " send "n\n" expect "Is this a remastered/snapshot install (y/N)? " send "n\n" expect "Type in your default user name: " send "bob\n" expect "New password: " send "bob1\n" expect "Retype new password: " send "bob1\n" expect -ex {Full Name []: } send "\n" expect -ex {Room Number []: } send "\n" expect -ex {Work Phone []: } send "\n" expect -ex {Home Phone []: } send "\n" expect -ex {Other []: } send "\n" expect -ex {Is the information correct? [Y/n] } send "y\n" expect "New password: " send "bob1\n" expect "Retype new password: " send "bob1\n" expect "Set autologin for bob: (y/N)? " send "n\n" expect "Cleaning up" expect eof ENDOFCLIINSTALLERSCRIPT -
AuthorPosts
- You must be logged in to reply to this topic.