1834939 Members
2332 Online
110071 Solutions
New Discussion

Moving passwd file

 
SOLVED
Go to solution
Mike Kapsak
Advisor

Moving passwd file

Hi,

I have a requirement to move the passwd file from one server to another only taking those user-id's accessed within the last 90 days. Can anybody point me in the right direction without getting overwhelmed?

Thanks,

Mike Kapsak
6 REPLIES 6
Ashwani Kashyap
Honored Contributor

Re: Moving passwd file

IF you are on a nontrusted system then copu your /etc/passwd file as /etc/passwd.old .

Then write a script using the command lastb to find out which users logged in during the past 90 days , remove entries for all other users in the passwd.old file , then copy this file onto your new server as /etc/passwd .
Sridhar Bhaskarla
Honored Contributor

Re: Moving passwd file

Hi Mike,

Try this way.

1. Run last -R > /tmp/success
2. "vi /tmp/success" and delete the entries that are more than 90 days old. Determine the
90 days old date (say Jun 23), search for it by using " :.,$d " in the vi session and save
the file.
3. Do "awk '{print $1}' /tmp/success |sort |uniq > /tmp/logins". Delete wtmp, root and other system logins from the list.
4. Now get the entries using

for i in `cat /tmp/logins`
do
grep ^$i /etc/passwd >> /tmp/passwd.delta
done

5. passwd.delta contains only user logins. Copy this to the other system and "append" it to the /etc/passwd file.

Things will be little bit complicated if you are using trusted systems.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Sridhar Bhaskarla
Honored Contributor
Solution

Re: Moving passwd file

Hi Mike,

Try this way.

1. Run last -R > /tmp/success
2. "vi /tmp/success" and delete the entries that are more than 90 days old. Determine the
90 days old date (say Jun 23), search for it by using " :.,$d " in the vi session and save
the file.
3. Do "awk '{print $1}' /tmp/success |sort |uniq > /tmp/logins". Delete wtmp, root and other system logins from the list.
4. Now get the entries using

for i in `cat /tmp/logins`
do
grep ^$i /etc/passwd >> /tmp/passwd.delta
done

5. passwd.delta contains only user logins. Copy this to the other system and "append" it to the /etc/passwd file.

Things will be little bit complicated if you are using trusted systems.

-Sri

PS: By the way, I do not know the scope of "overwhelming". We only try to help each other here.
You may be disappointed if you fail, but you are doomed if you don't try
Tom Maloy
Respected Contributor

Re: Moving passwd file

Well, I wouldn't move the password file - too much likelihood of conflicting user IDs.

If you want to see which users have had $HOME directory contents that have been changed in the last 90 days, assuming that they are all in /home:

find /home/* -mtime -90 -prune -print | cut -d"/" -f1 | sort -u

That might miss a few folks who didn't change any files. So you could try:

for i in `cut -f1 -d":" /etc/passwd`
do
last $i | head -1
done

You'd have to add something, probably using caljd.sh, to figure out the date. Or just redirect into a file and edit the list by hand.

Tom
Carpe diem!
Mike Kapsak
Advisor

Re: Moving passwd file

Thanks everyone for your help. BTW, the system I will move the passwd file to is not in use and therefore I don't have to worry about what already exists. I will try the recommendations and go from there.
Jim Walls
Trusted Contributor

Re: Moving passwd file

If these user's require login access , then, unless you intend importing the users' $HOME data from the original server, you will need to create a home directory for each user... and, as a minimum, copy the contents of /etc/skel to each.

Alternatively, you might want to set up one new user on the second system, to be used as a skeleton for the rest. Copy the contents of the skeleton user's virginal $HOME to each of the imported user's home directories.

Regards
Jim