LinuxQuestions.org
Help answer threads with 0 replies.
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 10-19-2011, 10:55 AM   #1
theillien
Member
 
Registered: Jan 2004
Posts: 112

Rep: Reputation: 1
Show new user accounts


Due to a contract stipulation, one of our security policies dictates that we stay informed of user accounts when they're added. We aren't required to use LDAP or any other centralized authentication scheme so I'm looking at scripting it. The idea is that it would run once a week letting us know if any accounts were added in the previous week and what they are.

Has anyone else ever done anything like this and is able to provide input on how to approach it? I have a preliminary script which does some file diff'ing, but it is rudimentary and not very effective.
 
Old 10-19-2011, 04:13 PM   #2
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
It seems as though they are trying to push a big chunk of governance onto the IT department. Surely good practice is for the hiring manager and HR to work together on a new hire and then the hiring manager will put through the paperwork which includes a request for a new user account and will gain approval from a registered approver. Then the service desk (because obviously you are ITIL compliant) will store the request and approval on the CMS and that will tie up with an account if required. Is there a problem with rogue accounts on your system and if so it would appear that you have a completely different problem than just logging accounts.
 
Old 10-19-2011, 04:14 PM   #3
theillien
Member
 
Registered: Jan 2004
Posts: 112

Original Poster
Rep: Reputation: 1
We don't have rogue accounts at the moment, but due to compliance we need to track such things to ensure we are not letting any slip through and go unnoticed.
 
Old 10-19-2011, 04:38 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
I agree standard procedures should be the start of the audit trail in terms of authorization and authentication. Practically speaking there's no need to script anything on PAM-aware systems as it logs any account manipulation which Logwatch then can report about. Same goes for audit-aware systems but then you want ausearch / aureport.
 
Old 10-19-2011, 04:54 PM   #5
theillien
Member
 
Registered: Jan 2004
Posts: 112

Original Poster
Rep: Reputation: 1
That's all well and good and I appreciate your input. However, the problem still stands. I need to send a report of new accounts that have been created on a weekly basis.

Can anyone help with this rather than offer opinion on policy?
 
Old 10-19-2011, 05:03 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
So Logwatch is of no use to you?
 
Old 10-19-2011, 05:33 PM   #7
theillien
Member
 
Registered: Jan 2004
Posts: 112

Original Poster
Rep: Reputation: 1
Can logwatch send me an email that lists only the accounts created in the last week without all the other stuff but also send me an email every week with all the other stuff?
 
Old 10-19-2011, 05:40 PM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
See 'man logwatch' the "--service pam" part? Else just cronjob a 'egrep "(user|group)add" /var/log/secure'.
 
Old 10-20-2011, 09:44 AM   #9
White Tea Citrus
LQ Newbie
 
Registered: Sep 2009
Location: Slovakia
Distribution: Trisquel 5.0 Dagda
Posts: 27

Rep: Reputation: 0
Hello!

Here is a fine script:

#!/bin/bash

cat /etc/passwd|awk -F : '{ print $1 }'|sort -nk1 > ~/desiredlogdirectory/passwd.newweek
diff ~/desiredlogdirectory/passwd.newweek ~/desiredlogdirectory/passwd.oldweek |grep -v '^$'|grep -v '^>'|grep -v '^---'|tail -n +2 > ~/desiredlogdirectory/newusers.week$(date +%V)
sed -i '1s/^/Please welcome our new users:\n/' ~/desiredlogdirectory/newusers.week$(date +%V)
mv ~/desiredlogdirectory/passwd.newweek ~/desiredlogdirectory/passwd.oldweek
cat ~/desiredlogdirectory/newusers.week$(date +%V)|wall


What do you think?
 
Old 10-27-2011, 10:49 AM   #10
theillien
Member
 
Registered: Jan 2004
Posts: 112

Original Poster
Rep: Reputation: 1
I appreciate the input.

This is the meat of what I've come up with:

Code:
#!/bin/bash

while [ read line ]
do
        arr=($line)
done < $(grep "new user" /var/log/secure |grep -v COMMAND |grep -v group |awk '{print $8}' |awk -F= '{print $2}' |sed '/^/ s/,$//')
I need to sort out how to best do this and only find entries from the previous week (search the previously rotated secure log or will the existing one work, etc.)

The only issue I think I'm going to have with this is that when I run the above to test that it works, the last entry shows up with ": No such file or directory" appended. Why would that happen?

-Mathew
 
Old 10-30-2011, 10:59 AM   #11
White Tea Citrus
LQ Newbie
 
Registered: Sep 2009
Location: Slovakia
Distribution: Trisquel 5.0 Dagda
Posts: 27

Rep: Reputation: 0
Hello Mathew,

I'm working on a solution

Filip

Last edited by White Tea Citrus; 10-30-2011 at 01:03 PM.
 
Old 10-30-2011, 01:16 PM   #12
White Tea Citrus
LQ Newbie
 
Registered: Sep 2009
Location: Slovakia
Distribution: Trisquel 5.0 Dagda
Posts: 27

Rep: Reputation: 0
Script for weekly report of new and deleted users to be put into crontab

Mathew,

So I prepared a script for what you were trying to do:

Code:
#!/bin/bash

if [ -a ~/YourLogDirectory/authlog.week$(( $(date +%V) -1 )) ]
then
cat /var/log/auth.log > ~/YourLogDirectory/authlog.new
TOBEGREPPED1=$(tail -n1 ~/YourLogDirectory/authlog.week$(( $(date +%V) -1 ))|sed "s/\[/\\\[/g"|sed "s/\]/\\\]/g")
THELINENO2=$(cat -n ~/YourLogDirectory/authlog.new |grep "$TOBEGREPPED1"|awk '{ print $1 }')
tail -n+$(( $THELINENO2 +1 )) ~/YourLogDirectory/authlog.new > ~/YourLogDirectory/authlog.week_$(date +%V)
grep -e "new user" -e "delete user" ~/YourLogDirectory/authlog.week_$(date +%V) > ~/YourLogDirectory/authlog.week$(date +%V)
echo "Here is the last timestamp for logrotate">>~/YourLogDirectory/authlog.week$(date +%V)
tail -n1 /var/log/auth.log >> ~/YourLogDirectory/authlog.week$(date +%V)
rm -f ~/YourLogDirectory/authlog.new
rm -f ~/YourLogDirectory/authlog.week_$(date +%V)
elif [ -a ~/YourLogDirectory/authlog.week* ]
then
tail -n1 /var/log/auth.log > ~/YourLogDirectory/authlog.week$(date +%V)
sed -i '1s/^/No new users were added however here is the timestamp for log rotation:\n/' ~/YourLogDirectory/authlog.week$(date +%V)
else
cat /var/log/auth.log| grep -e "new user" -e "delete user"> ~/YourLogDirectory/authlog.week$(date +%V)
fi
The sed there puts a backslash before any [ and ] so the whole last line of the previous week's log can be grepped. If you don't have an auth.log file, you'll probably have to add this sed for every char that causes grep to fail. For the grep part, you can use yours.

I hope you'll enjoy the script as I do.

Filip

Last edited by White Tea Citrus; 10-31-2011 at 11:02 AM.
 
  


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
Fedora 15 machine accounts show at login heals1ic Fedora 1 06-25-2011 01:32 PM
show all users accounts cccc Debian 2 02-20-2011 08:09 PM
Difference betwwen : Locked User Account & Disabled User Accounts in Linux ? avklinux Linux - Security 1 02-04-2009 02:30 PM
proftpd multi-user configuration, user cannot show contents of directories uglyoldbob Linux - Server 6 09-15-2008 11:18 PM

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

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