LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 04-04-2017, 06:29 AM   #1
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Rep: Reputation: 59
Setting Passwords from /etc/shadow file


Hi,


We have upgraded a RHEL 6 server to RHEL 7 and we do have backup of configs / system files. Now the customer wants to create users found in the old /etc/passwd from RHEL 6 but does not want us to touch /etc/shadow or /etc/passwd manually. The customer wants that user accounts that are not currently present in the current /etc/passwd file be created using "useradd" command (for example) and the related password from the /etc/shadow be taken instead of directly copying the user account's info from the old /etc/shadow file to the new /etc/shadow file.

I am currently doing my homework on Google but have not found a solution yet.

So, how do we use /etc/shadow for setting password for a new user account that used to exist earlier (in the old /etc/passwd and /etc/shadow) so that we can keep the same old password when creating the user account now since the new /etc/passwd and /etc/shadow files do not have the user account's entries?

Please let me know if my query is not clear.

In other words:

I have old /etc/passwd and /etc/shadow files.

The new /etc/passwd and /etc/shadow files do have entry for user account "Jack".

Now I create the user account "Jack" using:

useradd Jack

and need to use the same password according to the old /etc/shadow file.

I am wondering as to how to do that.
 
Old 04-04-2017, 06:38 AM   #2
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
I have answered the question myself, however, I will keep this post open for sometime if there is another way to do it.

My Solution / Finding:

By reading the help section of "useradd" command I got to know about -p or --password option that does the work I want to do:

useradd Max -p `grep Jack /etc/shadow | cut -d ":" -f2`

Now I can login as Max using the same password as set for Jack in the /etc/shadow file.
 
1 members found this post helpful.
Old 04-04-2017, 06:50 AM   #3
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Good stuff. I'm keeping it.
 
Old 04-04-2017, 07:54 AM   #4
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
The customer is right to want to do this an alternative way as it is a bad idea to copy /etc/passwd and /etc/shadow from RHEL 6 to RHEL 7 as there is a very big change between them to consider. In RHEL 6, anything up to uid 500 is reserved for system accounts whereas in RHEL 7, anything up to uid 1000 is reserved for system accounts. While you can change/reconfigure it, it isn't advisable.

Given uids for normal users start at 500 in RHEL 6... the moment you copy those over to RHEL 7, you are inviting yourself to have some "fun" issues.

Last edited by r3sistance; 04-04-2017 at 11:25 AM.
 
1 members found this post helpful.
Old 04-04-2017, 07:46 PM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
The only change that I'd suggest to the above "trick" is ... that you deliberately break it down into a series of smaller steps.

For instance, "first run that grep/cut sequence to create a file ... containing the proposed(!) set of changes."[/i] Then, open the sucker up and carefully eyeball it. Then, perhaps, use xargs to execute the actual commands.

The customer's reasoning, and your general solution, is quite sound. Although you might, with rootly powers, compare two lists (one of them being the "shadow" file) ... n-e-v-e-r attempt to modify such files directly.
 
1 members found this post helpful.
  


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
[SOLVED] What should the permission setting for the /etc/shadow file be? chris1973 Linux - Newbie 3 08-15-2010 02:21 AM
[SOLVED] What encryption does the /etc/shadow file use for passwords? Karas Linux - Newbie 4 11-26-2009 06:01 PM
EDK corrupted all my passwords? Can't find /etc/shadow file to edit! fy1000000 Linux - Newbie 27 05-22-2009 10:46 AM
shadow passwords help? SciYro Linux - Security 2 03-03-2004 05:11 AM
shadow passwords dtheorem Linux From Scratch 2 10-18-2003 11:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 06:22 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