Sponsored Content
Top Forums Shell Programming and Scripting Maintain health of passwd file Post 302687109 by Learn4Life on Thursday 16th of August 2012 03:42:31 AM
Old 08-16-2012
Maintain health of passwd file

Hello guys

I am about to write a script that is based on "The Linux Administration Handbook" The exercise is as follows:

Write a shell script to help monitor the health of the /etc/passwd file.
  1. Find entries that have UID0
  2. Find entries that have no password (needs /etc/shadow)
  3. Find any sets of entries that have duplicate UID's
  4. Find entries that have duplicate login names
  5. find entries that have no expiration date (needs /etc/shadow)
I finished point 1,3, and 4. What I am not able to figure out is how to access the shadow file without being root. I thought maybe by exec su | sh, and then access the file. But the user shouldn't have to interact with the script. Here is what I have so far


Code:
#!/usr/bin/sh
#
# SCRIPT:    lab5
# AUTHOR:    
# DATE:        8/15/2012
# REV:        1.0A
# PLATFORM:    Linux
# PURPOSE:    Maintain Health of the /etc/passwd file by checking for 
#        duplicate UID's, root ID, duplicate login names,
#        expiration date, entries with no password.
#
#
# REV LIST:
#    DATE:    8/16/2012
#    BY:    
#    MDIFICATION:    add awk for duplicate UID and login name check.
#
#
#
###############################################################################
##################### DEFINE FILES AND VARIABLES HERE #########################
###############################################################################

#    NO VARIABLES


###############################################################################
######################### DEFINE FUNCTIONS HERE ###############################
###############################################################################


#    NO FUNCTIONS


###############################################################################
######################### BEGINNING OF MAIN ###################################
###############################################################################

# This line checks for the root ID. It notifies the user if the root ID 
# exists or not.
echo "Check for root uid..."
awk -F: '$1 = ~/root/ {print "Found Root ID"} ' /etc/passwd        

# Check for duplicate UID by reading the records into an awk array
# and compare the predecessor with the successor. If the comparison 
# result is greater as 1 print the duplicate value.
echo "Check for duplicate UID's..."
awk -F:  'uname[$3]++ && uname[$3]>1 {print "duplicate user:", $1} ' /etc/passwd
echo "Duplicate UID check done"


# Check for duplicate UID by reading the records into an awk array
# and compare the predecessor with the successor. If the comparison 
# result is greater as 1 print the duplicate value.
echo "Check for duplicate user names..."
awk -F:  'uid[$3]++ && uid[$3]>1 {print "duplicate uid:", $3}' /etc/passwd
echo "Duplicate user name check done."

echo "Check for passwords..."

# I am not sure about that one !
#`exec su | sh | awk -F: '$2 ~/$\d$/ {print "User $1 has password}' /etc/shadow |  exit` 
exit 0


# End of Script

Any ideas, hints, advice etc. is greatly appreciated. Thank you.

-Daniel
 

10 More Discussions You Might Find Interesting

1. Cybersecurity

/etc/passwd file

hi Does anyone anyone know what the last line of a unix user passwd file signifes? Mine shows "+:::::" best (4 Replies)
Discussion started by: s_mad010
4 Replies

2. Shell Programming and Scripting

help in /etc/passwd file

Hi all, As all of us know that in /etc/passwd file the first field correspond to username could any one tell me what is bin , damoen etc in the first field, and r they in user field , what is nologin in the last column ? root:x:0:0:root:/root:/bin/bash ... (4 Replies)
Discussion started by: useless79
4 Replies

3. UNIX for Dummies Questions & Answers

sed a file and maintain date stamp and permissions

I need to alter a file. I'm using sed then passing output to temp file then using touch -r to maintain the date but the permissions do not get preserved How can I sed a file and maintain date and permissions currently it's preserving the date but the permissions revert back to the... (3 Replies)
Discussion started by: andyatit
3 Replies

4. Solaris

passwd cmd reenables passwd aging in shadow entry

Hi Folks, I have Solaris 10, latest release. We have passwd aging set in /etc/defalut/passwd. I have an account that passwd should never expire. Acheived by emptying associated users shadow file entries for passwd aging. When I reset the users passwd using passwd command, it re enables... (3 Replies)
Discussion started by: BG_JrAdmin
3 Replies

5. UNIX for Dummies Questions & Answers

help with passwd file

Not an unix expert, I read a few pages on the web about passwd files, but I didn't find the answers I need about the last 8 lines of the passwd file I'm taking a look at. I'm assuming their shortcuts to another file that may have the actual usernames of users on the system. Please, any help... (1 Reply)
Discussion started by: fusion31
1 Replies

6. Shell Programming and Scripting

Script to maintain file versions

I am developing a script to maintain 'n' number of versions of a file. The script will take a filename as a parameter and the number of versions to maintain. This basically does something like a FIFO. Here is what I developed. But something is not right. I have attached the script. Can u pls help... (2 Replies)
Discussion started by: vskr72
2 Replies

7. AIX

When did AIX start using /etc/security/passwd instead of /etc/passwd to store encrypted passwords?

Does anyone know when AIX started using /etc/security/passwd instead of /etc/passwd to store encrypted passwords? (1 Reply)
Discussion started by: Anne Neville
1 Replies

8. Homework & Coursework Questions

Maintain health of passwd file

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Hello guys I am about to write a script that is based on "The Linux Administration Handbook" The exercise is... (6 Replies)
Discussion started by: Learn4Life
6 Replies

9. UNIX for Advanced & Expert Users

How to maintain a personal password file 'safely'?

Hi all, As time progresses, the number of servers that I have to login to has grown to the hundreds. Some of the servers has NIS so I can use one single password for this group of servers. The hard part comes to when you have 20+ other servers that now require different passwords and... (4 Replies)
Discussion started by: newbie_01
4 Replies

10. UNIX for Advanced & Expert Users

Removing special chars from file and maintain field separator

Running SunOs 5.6. Solaris. I've been able to remove all special characters from a fixed length file which appear in the first column but as a result all subsequent columns have shifted to the left by the amount of characters deleted. It is a space separated file. Line 1 in input file is... (6 Replies)
Discussion started by: iffy290
6 Replies
CHSH(1) 							   User Commands							   CHSH(1)

NAME
chsh - change login shell SYNOPSIS
chsh [options] [LOGIN] DESCRIPTION
The chsh command changes the user login shell. This determines the name of the user's initial login command. A normal user may only change the login shell for her own account; the superuser may change the login shell for any account. OPTIONS
The options which apply to the chsh command are: -h, --help Display help message and exit. -s, --shell SHELL The name of the user's new login shell. Setting this field to blank causes the system to select the default login shell. If the -s option is not selected, chsh operates in an interactive fashion, prompting the user with the current login shell. Enter the new value to change the shell, or leave the line blank to use the current one. The current shell is displayed between a pair of [ ] marks. NOTE
The only restriction placed on the login shell is that the command name must be listed in /etc/shells, unless the invoker is the superuser, and then any value may be added. An account with a restricted login shell may not change her login shell. For this reason, placing /bin/rsh in /etc/shells is discouraged since accidentally changing to a restricted shell would prevent the user from ever changing her login shell back to its original value. FILES
/etc/passwd User account information. /etc/shells List of valid login shells. /etc/login.defs Shadow password suite configuration. SEE ALSO
chfn(1), login.defs(5), passwd(5). User Commands 06/24/2011 CHSH(1)
All times are GMT -4. The time now is 01:51 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy