Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I want to create a new user in a specific group when I issue the below command.

sudo ./create_user.sh "test" "firstname lastname"

The create_user.sh script looks as below.

#!bin/bash
#sudo adduser --gecos "$2" --ingroup testgroup $1

However, the problem is, I have to avoid the password insertion (it should be simply test) with a here document, but I have no idea about the syntax.

I tried some solutions but none of them seemed to work.

This is how my Try to of the heredocument in the script looks like

#<< EOF
#test
#test
#EOF

my output looks like this

#adding user 'test' ...
#adding new user 'test' <1003> with group 'testgroup' ...
#Enter new UNIX password:
share|improve this question
    
Can you not pass the -p flag in the script to the adduser command if you're going to pass the password in the script anyway? –  Dayvo Jan 5 at 18:49
    
unfortunately not... its about learning the here document, i have to use it. –  Newguy Jan 5 at 19:23

1 Answer 1

adduser calls the passwd utility to set a password. Like many programs that prompt for a password, passwd insists that its output comes from a terminal. So you cannot pass it input via a here-document — that creates a temporary file or a pipe, and passwd accepts neither.

You can pas adduser (at least the Debian version) the --disabled-password option if you don't want to be able to log in with a password (you'll still be able to log in with other methods such as SSH keys if you set them up). adduser doesn't have an option to pass the password hash (not the password itself), but useradd from the Linux shadow password utility suite does.

If you want to enter a password during the account creation, make sure that passwd reads from the terminal. If you obtain the password from some other source (e.g. a web form), call passwd from an expect script — example.

If this is an exercise in using a here document, the password is not where you should use it. I don't see any problem that a here document would solve in what you've posted.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.