Modify /etc/passwd via script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Modify /etc/passwd via script
# 1  
Old 03-23-2011
Modify /etc/passwd via script

We have a business need to modify the /etc/passwd file every time a new user gets added, because the user ID begins with a zero. When you create the new user in smit, even if you put the leading zero in, it does not retain it when the entry is added.

That being said, I need to create a script that will take an argument (the username) and append the zero to the beginning of the user ID field.

Anyone have any suggestions?

Thanks in advance!
# 2  
Old 03-23-2011
I should note, from man useradd:
Code:
CAVEATS
...

       Usernames must start with a lower case letter or an underscore,
       followed by lower case letters, digits, underscores, or dashes. They
       can end with a dollar sign. In regular expression terms:
       [a-z_][a-z0-9_-]*[$]?

So it's not just smit that disallows these usernames, it's a general login requirement. If you force /etc/passwd to contain these entries it may misbehave, violate it at your own risk.

You should be able to get away with _0username if that will work for your purposes.

Do you have usermod available? You can do usermod -l _0username username to avoid the peril of editing /etc/passwd yourself.

Last edited by Corona688; 03-23-2011 at 05:17 PM..
# 3  
Old 03-23-2011
its no the username, but the uid that needs to be appended with a zero. This is because our LDAP configuration requires that the uid in unix match the uid in the LDAP tree and our business uses leading zeros in LDAP. I have an idea and am working on it but anything else you think of would be great.

---------- Post updated at 04:16 PM ---------- Previous update was at 04:16 PM ----------

bah, this is aix 6.1 if that helps
# 4  
Old 03-23-2011
I've never seen leading zeroes in a UID or GID and can't predict the potential side-effects of adding them. They might go away of their own accord any time you edit that user again, for that matter. They're not supposed to be strings and won't be processed as such. Hopefully most things will just ignore them but that's no guarantee.

Are you absolutely sure there's absolutely no way to just have them exported with a leading zero as far as your NIS config is concerned or something? Hand-butchering your /etc/passwd file should be an absolute last resort.
# 5  
Old 03-23-2011
This is a process that I inherited from years of doing it this way. the departments here are so separated, reverse engineering this whole thing would be a nightmare. I agree that hand modifying the passwd file is ridiculous but im not sure working to change this process would get me far. Appending the zero has not caused any ill results over the years until today when someone with sudo privileges accidentally deleted the root line, effectively breaking the whole system. A few hours later and we are back, now we need to limit who touches it, hence the need for a script.

I have something in the works.
# 6  
Old 03-24-2011
I'm lost here. If you're using LDAP why are the users in /etc/passwd?
# 7  
Old 03-24-2011
our application spawns unix shell processes and it is not LDAP authenticated so it still uses the passwd file. band aid after band aid after band aid and you get the world I've inherited Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Modify python script

How can I modify this so it uses Seamonkey and goes to Yahoo Advanced Web Search #!/usr/bin/python3 import os import urllib google = os.popen('zenity --entry --text="Enter what you want to google: " --title="google.py"').read() google = urllib.quote(google) os.system('firefox... (8 Replies)
Discussion started by: drew77
8 Replies

2. Shell Programming and Scripting

Modify the file by script

Hi All, I have an input file like below, 6984 1225 6989 1220 6994 1214 ... (3 Replies)
Discussion started by: Indra2011
3 Replies

3. 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

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. Shell Programming and Scripting

how can I modify this script.

hello forum members, I have a script which is used find the Uname and passwords and redirects into a output.txt file.I hardcoded a string "ciadev" but iwant search two more strings also "absdev" and "absprod" So modify this script please. I am lookinmg forward from you, please find the below... (2 Replies)
Discussion started by: rajkumar_g
2 Replies

6. Shell Programming and Scripting

script to modify /etc/shadow

Hi I am looking for script to modify /etc/shadow. For example: 1-)User enters username 2-)The line of that user is found in /etc/shadow and *LK* is added infront of the second field in /etc/shadow. How can I do this? Thanks (7 Replies)
Discussion started by: tjay83
7 Replies

7. Shell Programming and Scripting

Please help to modify my script

Hi, I have a script which connect to ATM's and pull two files from the ATM. The which i try to pull is like PIC20085200001*.JPG First 7 digit consist of year montn and date as well After todays execution i want to change the date to next date I add few lines in the script but it is not... (6 Replies)
Discussion started by: Renjesh
6 Replies

8. Shell Programming and Scripting

Modify Perl script to work with txt - Permissions script

Hi I have this code, and i want work with a ls -shalR output in .txt What i need read to do this?? Where start? #!/usr/bin/perl # Allrights- A perl tool for making backups of file permissions # Copyright (C) 2005 Norbert Klein <norbert@acodedb.com> # This program is free... (1 Reply)
Discussion started by: joangopan
1 Replies

9. UNIX for Dummies Questions & Answers

Using a script to modify the crontab

I want to add one line to the end of my crontab using a script. I have tried piping in the editor commands, but I can't get it to work. crontab -e user << EX $a This is the text I want to add. . wq EX This doesn't work. Is there an easier way to do this? (2 Replies)
Discussion started by: johnmsucpe
2 Replies

10. Shell Programming and Scripting

passwd -l script

I need to lockout about 250 user accounts on a server. I figure on putting the user accounts to be locked out in a text file and the running a script to go through the file and run the "passwd -l useraccount" against the /etc/passwd file (yes, I am root as I do this). Here is what I have so... (3 Replies)
Discussion started by: antalexi
3 Replies
Login or Register to Ask a Question