LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-25-2009, 05:25 AM   #1
jonaskellens
Member
 
Registered: Jul 2008
Location: Ghent, Belgium
Distribution: Fedora, CentOS
Posts: 690

Rep: Reputation: 34
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...
 
Old 09-25-2009, 05:31 AM   #2
JamesChamberlain
Member
 
Registered: Sep 2009
Location: Wirral, UK
Distribution: Red Hat Enterprise Linux / Fedora 11
Posts: 47

Rep: Reputation: 18
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.
 
Old 09-25-2009, 05:35 AM   #3
jonaskellens
Member
 
Registered: Jul 2008
Location: Ghent, Belgium
Distribution: Fedora, CentOS
Posts: 690

Original Poster
Rep: Reputation: 34
Quote:
Originally Posted by JamesChamberlain View Post
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`
 
Old 09-25-2009, 05:50 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
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
 
Old 09-25-2009, 06:08 AM   #5
jonaskellens
Member
 
Registered: Jul 2008
Location: Ghent, Belgium
Distribution: Fedora, CentOS
Posts: 690

Original Poster
Rep: Reputation: 34
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...
 
Old 09-25-2009, 06:13 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Try adding these 2 lines to /etc/rc.local

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


replace $USER with reqd username
 
Old 09-25-2009, 06:31 AM   #7
jonaskellens
Member
 
Registered: Jul 2008
Location: Ghent, Belgium
Distribution: Fedora, CentOS
Posts: 690

Original Poster
Rep: Reputation: 34
Quote:
Originally Posted by chrism01 View Post
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...

Last edited by jonaskellens; 09-25-2009 at 06:33 AM.
 
Old 09-25-2009, 07:19 AM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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
 
Old 09-25-2009, 08:34 AM   #9
jonaskellens
Member
 
Registered: Jul 2008
Location: Ghent, Belgium
Distribution: Fedora, CentOS
Posts: 690

Original Poster
Rep: Reputation: 34
Quote:
Originally Posted by chrism01 View Post
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 ?!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
/usr/sbin/httpd: symbol lookup error: /usr/sbin/httpd: undefined symbol: apr_atomic_x dasoberdick Slackware 16 10-11-2014 02:36 AM
passwd command says BAD PASSWORD planetmars Linux - Newbie 9 09-19-2009 04:42 AM
127 Can't execute command '/usr/sbin/sendmail kiganda Linux - Newbie 1 10-03-2007 05:50 AM
/usr/sbin/sudo: line 1: root: command not found saheelahamed Linux - Software 2 08-02-2007 07:14 AM
What is difference between /usr/sbin/ps & /usr/ucb/ps command rajaniyer123 Solaris / OpenSolaris 6 07-05-2007 12:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration