LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   give password with command /usr/sbin/passwd (https://www.linuxquestions.org/questions/linux-newbie-8/give-password-with-command-usr-sbin-passwd-757691/)

jonaskellens 09-25-2009 05:25 AM

give password with command /usr/sbin/passwd
 
Everytime the server reboots I want to create a user at boot. For some reason I loose my user after a reboot.

So I thought I'd create a script that creates this user (in rc.local for example)

Therefore I need to give the password directly with the command /usr/bin/passwd.

I can't find in the man-page how a password can immediately be given with the command...

JamesChamberlain 09-25-2009 05:31 AM

Hm, im not to sure..

Perhaps auto making an entry in /etc/passwd would do it?

Would look something like this:

james:K3xcO1Qnx8LFN:1000:1000:,,,1-800-FOOBAR:/home/james:/bin/bash

The "K3xcO1Qnx8LFN" bit being the encrypted pass.

jonaskellens 09-25-2009 05:35 AM

Quote:

Originally Posted by JamesChamberlain (Post 3696615)
Hm, im not to sure..

Perhaps auto making an entry in /etc/passwd would do it?

Would look something like this:

james:K3xcO1Qnx8LFN:1000:1000:,,,1-800-FOOBAR:/home/james:/bin/bash

The "K3xcO1Qnx8LFN" bit being the encrypted pass.

I could put this in rc.local ?
Code:

useradd my-user -p `mkpasswd mypasswd`

bathory 09-25-2009 05:50 AM

First of all you should find out why you lose your user when your box reboots
You can use newusers to do what you want. Create a file.txt like this:
Code:

username:password:XXXX:YYY::/home/user:/bin/bash
where XXXX: uid, YYY: gid
and then run on boot:
Code:

/usr/sbin/newusers /path/to/file.txt

jonaskellens 09-25-2009 06:08 AM

I put /usr/sbin/useradd my-user in rc.local but my user is not created ?!

When I run /usr/sbin/useradd my-user from commandline, then the user is created...

chrism01 09-25-2009 06:13 AM

Try adding these 2 lines to /etc/rc.local

useradd $USER
echo password | passwd --stdin $USER


replace $USER with reqd username

jonaskellens 09-25-2009 06:31 AM

Quote:

Originally Posted by chrism01 (Post 3696648)
Try adding these 2 lines to /etc/rc.local

useradd $USER
echo password | passwd --stdin $USER


replace $USER with reqd username

Tried this... no errors at boot but :
Code:

[root@box]# cat /etc/passwd | grep user
nothing...

I just can't get this user created at startup...

chrism01 09-25-2009 07:19 AM

I think we need to backtrack.

1. can you create a new user and passwd after you have logged in as root? ie no errors.
show contents of /etc/passwd, /etc/shadow
If not, show error msgs

2. If create went ok, can you then login as that user? If not, show error msgs

jonaskellens 09-25-2009 08:34 AM

Quote:

Originally Posted by chrism01 (Post 3696705)
I think we need to backtrack.

1. can you create a new user and passwd after you have logged in as root? ie no errors.
show contents of /etc/passwd, /etc/shadow
If not, show error msgs

2. If create went ok, can you then login as that user? If not, show error msgs

After reboot, as root-user I create the user as followed :
/usr/sbin/useradd my-user

and then everything is fine... don't even need a password. It is still intact...
Code:

[root@box]# cat /etc/passwd | grep user
my-user:x:1004:1004::/home/my-user:/bin/bash
[root@box]# cat /etc/shadow | grep user
my-user:!!:14512:0:99999:7:::

So I guess only the entry in /etc/passwd has disappeared...

Still don't understand why placing "/usr/sbin/useradd my-user" in rc.local is not enough... as it IS enough on commandline.

rc.local is executed as root-user, right ?!


All times are GMT -5. The time now is 03:47 PM.