• Rob's side project: I recently started Gun-Forums.com and we currently have a $100 raffle - if you're into guns, join up and enter the raffle to win $100.00. Gun Forums

Zenity - Create new user and password creator

superboy2k6

Member
Hi,
Is there any way to use zenity to create new user along with a password.
I would like to create a shell script of it. I know python very well but not much about shell scripting. My first try was (absolutely wrong):
Code:
$data=zenity --password
echo $data
useradd -m liveuser
passwd liveuser $data
su liveuser
exit
And as I expected, it didn't work

Any help?
Cheers, superboy.
 


impossible

New Member
try something like this :

#!/bin/bash
zenity --password > test
cat test >> test1
cat test >> test1
useradd -m liveuser
passwd liveuser < test1
rm test test1
su liveuser
exit


then give x permission for the created file and then execute
 

superboy2k6

Member
The code you gave works like a charm!

What I understood from your code is that you created a temporary file test and made another file called test1 and transferred your code to it. You then set the password as the username1 file and delete both of these files. Pretty awesome! (Correct me if my explanation is wrong)

Now what to do if I want to create a user AND a password for the user??
The code below doesn't work:
Code:
#!/bin/bash
zenity --info --text='Welcome to Account Creation Wizard'
zenity --entry --text='What do you want to set your username as?' > username
zenity --password > test
cat username >> username1
cat username >> username1
cat test >> test1
cat test >> test1
useradd -m < username1
passwd < username1 < test1
rm test test1
rm username username1
exit
It gives me this:
Code:
[[email protected] Desktop]# ./UserCreator.sh
Usage: useradd [options] LOGIN
       useradd -D
       useradd -D [options]

Options:
      --badnames                do not check for bad names
  -b, --base-dir BASE_DIR       base directory for the home directory of the
                                new account
      --btrfs-subvolume-home    use BTRFS subvolume for home directory
  -c, --comment COMMENT         GECOS field of the new account
  -d, --home-dir HOME_DIR       home directory of the new account
  -D, --defaults                print or change default useradd configuration
  -e, --expiredate EXPIRE_DATE  expiration date of the new account
  -f, --inactive INACTIVE       password inactivity period of the new account
  -g, --gid GROUP               name or ID of the primary group of the new
                                account
  -G, --groups GROUPS           list of supplementary groups of the new
                                account
  -h, --help                    display this help message and exit
  -k, --skel SKEL_DIR           use this alternative skeleton directory
  -K, --key KEY=VALUE           override /etc/login.defs defaults
  -l, --no-log-init             do not add the user to the lastlog and
                                faillog databases
  -m, --create-home             create the user's home directory
  -M, --no-create-home          do not create the user's home directory
  -N, --no-user-group           do not create a group with the same name as
                                the user
  -o, --non-unique              allow to create users with duplicate
                                (non-unique) UID
  -p, --password PASSWORD       encrypted password of the new account
  -r, --system                  create a system account
  -R, --root CHROOT_DIR         directory to chroot into
  -P, --prefix PREFIX_DIR       prefix directory where are located the /etc/* files
  -s, --shell SHELL             login shell of the new account
  -u, --uid UID                 user ID of the new account
  -U, --user-group              create a group with the same name as the user

New password: Retype new password: passwd: password updated successfully
[[email protected] Desktop]#
Oh and this happens after entering the username and password. No new user is created. Weird enough that 'passwd' says that it updated successfully. Did it change my current password? :O
 
Last edited:


Members online


Latest posts

Top