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 - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-07-2011, 08:19 AM   #1
redrat
Member
 
Registered: Sep 2011
Posts: 31

Rep: Reputation: Disabled
Cool Moving /etc/passwd and /etc/shadow in a read-only system Red Hat 6


Hello, everybody,

i'm using Red Hat 6, I have two partitions in my computer:

- a 1st partition in read-only for /;

- a 2nd partition in read-write for /var.

I want to keep theses partitions.

I create new accounts with the
command useradd and passwd but it doesn't
run because the files /etc/passwd and /etc/shadow are in the read-only
partition.

Well, I use this solution:

I move the files /etc/passwd
and /etc/shadow to /var partition which is in read-write :
mv /etc/passwd /var
mv /etc/shadow /var

and I create these symbolics links :

ln -s /var/passwd /etc/passwd
ln -s /var/shadow /etc/shadow

When I reboot my system, i can login in red hat with my root account.

But when i open a shell console and i want to create new accounts with useradd and passwd : it doesn't run.

The system don't succeed to write in /var/passwd and /var/shadow and I don't know why.

Anyone has a solution to my problem ?


Thank you.
 
Old 09-07-2011, 08:21 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
erm, the solution is to NOT have a read only / partition. Why on earth would you do that??
 
Old 09-07-2011, 08:39 AM   #3
redrat
Member
 
Registered: Sep 2011
Posts: 31

Original Poster
Rep: Reputation: Disabled
The context is an engeneering project for which i must keep the / partition in read-only mode.

I don't have to put this / partition in read-only mode, it's a requirement.

So another solution ?
 
Old 09-07-2011, 10:43 AM   #4
tbrand
Member
 
Registered: Jul 2006
Location: Toronto, Canada
Distribution: gentoo
Posts: 33

Rep: Reputation: 17
I'm assuming that useradd and passwd cannot open the symbolic links for writing because they are in read only file system.

If you are using only the most basic functionality of useradd it would not be too difficult to write your own ``useradd'' that updates /var/passwd and /var/shadow directly. To encrypt passwords use the crypt() function.
 
Old 09-07-2011, 03:14 PM   #5
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,627

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
a requirement is to NEVER be able to install updates
never add users
never fix anything
never add software
????

you are out of luck

if everything but the logs are read ONLY
you do not.

you might boot into the "recovery" mode on the install dvd and after " chroot /mnt/sysimage "
edit the files in VI ( or nano )
 
Old 09-08-2011, 01:07 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
As above, you seem to be shooting yourself in the foot, but if you want it ro most of the time, but root may add users etc, then consider (as root)
Code:
mount -o remount,rw /

useradd ...

mount -o remount,ro /
and so on for updates to OS SW.
Don't forget also that with RH derived systems, you'll run into SELinux issue if you try to move/link protected files around.
 
Old 09-08-2011, 06:18 AM   #7
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
There is the option -P to useradd to specify a different directory for the files in question.
 
Old 09-08-2011, 09:26 AM   #8
redrat
Member
 
Registered: Sep 2011
Posts: 31

Original Poster
Rep: Reputation: Disabled
Cool Red Hat :where i can find the source code of useradd

Hello,

in the installation cd of RHEL6, I have the package shadow-utils-4.1.4.2-9.el6.i686.rpm,

i got the binary of useradd , but i can't find the source code?

Anyone have a suggestion to find this ?

Thanks.
 
Old 09-08-2011, 10:00 AM   #9
andrewthomas
Senior Member
 
Registered: May 2010
Location: Chicago Metro
Distribution: Arch, Gentoo, Slackware
Posts: 1,690

Rep: Reputation: 312Reputation: 312Reputation: 312Reputation: 312
http://rpm.pbone.net/index.php3/stat...-9.el6.src.rpm
 
Old 09-08-2011, 03:09 PM   #10
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,627

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
Quote:
in the installation cd of RHEL6, I have the package shadow-utils-4.1.4.2-9.el6.i686.rpm,
red hat requires a paid for license to install software

use your paid for and activated account and install the source from the rhn
Code:
su -
yum search shadow-utils
that will give you a listing .There will be a "-devel" or if you turned on the source rpeo then there will also be a src.rpm
then install it

but on a READONLY /
you can not install anything
there is no way to install any program to a read only /
 
Old 09-08-2011, 03:42 PM   #11
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
Quote:
Originally Posted by redrat
The context is an engeneering project for which i must keep the / partition in read-only mode.

I don't have to put this / partition in read-only mode, it's a requirement.
Having only two filesystems (read-only / and read-write /var) is not feasible.

Just for many processes to run you need a writable /tmp. And many package installations will require a writable /bin, /usr, /lib, /etc, and/or /sbin (in addition to /var).

Back to the drawing board with the project requirements. Your engineers do not seem to have thought this through very carefully.
 
1 members found this post helpful.
Old 09-12-2011, 04:28 AM   #12
redrat
Member
 
Registered: Sep 2011
Posts: 31

Original Poster
Rep: Reputation: Disabled
Hello, everybody,

I am treating my problem with the two partitions:
- the / partition in read-only ;
- the /var partition in read-write which will contain the files passwd, login, shadow, gshadow.

I got the package shadow-utils-4.1.4.2-9.el6.src.rpm which contains the source codes of the executables useradd, login, passwd ...

In this package there is the file "defines.h" which contains these lines:

#ifndef PASSWD_FILE
#define PASSWD_FILE "/etc/passwd"
#endif

#ifndef GROUP_FILE
#define GROUP_FILE "/etc/group"
#endif

#ifndef SHADOW_FILE
#define SHADOW_FILE "/etc/shadow"
#endif

#ifdef SHADOWGRP
#ifndef SGROUP_FILE
#define SGROUP_FILE "/etc/gshadow"
#endif
#endif

I replace theses lines by :

#ifndef PASSWD_FILE
#define PASSWD_FILE "/var/passwd"
#endif

#ifndef GROUP_FILE
#define GROUP_FILE "/var/group"
#endif

#ifndef SHADOW_FILE
#define SHADOW_FILE "/var/shadow"
#endif

#ifdef SHADOWGRP
#ifndef SGROUP_FILE
#define SGROUP_FILE "/var/gshadow"
#endif
#endif

I run the script "configure"( which is in the package) to get the Makefile, then i execute the command "make".

I got the new executables useradd, passwd, login ...

I replace the old executables by the new ones (in the repertories /usr/sbin; /usr/bin or /bin).

I move the files passwd, login, shadow, gshadow to /var.

I create these links :
ln -s /var/passwd /etc/passwd
ln -s /var/shadow /etc/shadow
ln -s /var/gshadow /etc/gshadow
ln -s /var/group /etc/group

I test the solution:

Well i can :

-add a user;
-create a password;
-change a password of a user;

But when i reboot the computer, the system recognize no users at the startup (user created or user root).

I don't understand why ?

Anyone have a suggestion ?

Thanks.
 
Old 09-12-2011, 07:59 AM   #13
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Probably because /var isn't mounted at the right time, can I ask why you're doing this?
 
Old 09-12-2011, 08:30 AM   #14
redrat
Member
 
Registered: Sep 2011
Posts: 31

Original Poster
Rep: Reputation: Disabled
It's for an engineering project in which the root partition must be in read-only and /var in read-write.

But /var partition is present in /etc/fstab ?

So /var is mounted at the startup of the system ?

It's good or not ?
 
Old 09-12-2011, 11:23 AM   #15
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
If you changed all programs to look in /var the symbolic links shouldn’t be necessary. Anyway: any output in /var/log which could point to the reason?
 
  


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
LXer: Alan Cox: Moving on from Red Hat LXer Syndicated Linux News 0 12-23-2008 10:30 AM
Moving user accounts between computers (Something wrong with passwd, shadow, etc.) Lionhard Linux - Software 5 01-18-2008 08:53 PM
Moving portions of /etc/passwd and /etc/shadow skreaminskull Linux - Security 3 05-19-2006 10:35 AM
Moving /etc/passwd and /etc/shadow john8675309 Linux - Software 1 01-24-2005 08:44 PM
recover root passwd red hat 8 simquest Linux - Software 1 09-17-2003 10:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:35 AM.

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