Replace password field using ed/sed


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Replace password field using ed/sed
# 1  
Old 04-27-2007
Replace password field using ed/sed

I need to edit the password file to change the password field to *LK* for a specified account (abctest) like:
abctest:*LK*:135:20::/home/abctest:/sbin/sh

Can anyone help me do this using ed or sed?

Thanks a lot!
# 2  
Old 04-27-2007
If manipulating the passwd file directly I would suggest you use the safer alternative which is awk.

In this case however, why not just use the system provided command for doing this, usually the passwd or usermod commands have an option for locking accounts.
# 3  
Old 04-28-2007
I am using the password command for all supported systems except hp10.20 which has no command to lock the password.

How can it be done with awk?

Thanks
# 4  
Old 04-28-2007
Code:
awk -F ":" 'BEGIN{OFS = ":"} /youruser/{$2="*LK*"}{ print}' /etc/passwd

please use at own risk.

Last edited by ghostdog74; 04-28-2007 at 02:42 AM..
# 5  
Old 04-30-2007
MySQL It worked for me

Thanks sooo much! I will be careful!
# 6  
Old 04-30-2007
Quote:
Originally Posted by ghostdog74
Code:
awk -F ":" 'BEGIN{OFS = ":"} /youruser/{$2="*LK*"}{ print}' /etc/passwd

please use at own risk.
Actually you should not use this code, a partial match will result in locking the wrong user.

eg users: user2 and user23 projectuser234 , using user2 will lock all three.

Code:
awk  'BEGIN{IFS = OFS = ":"} $1 == "youruser" { $2 = "*LK*" } { print }' /etc/passwd

# 7  
Old 05-01-2007
Quote:
Originally Posted by reborg
Actually you should not use this code, a partial match will result in locking the wrong user.

eg users: user2 and user23 projectuser234 , using user2 will lock all three.

Code:
awk  'BEGIN{IFS = OFS = ":"} $1 == "youruser" { $2 = "*LK*" } { print }' /etc/passwd

ah yes.. i missed out that one, should be == instead. tks
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to replace last field in a file,if first field matches

Hi, Need to replace last field in a file(/etc/passwd) ,if first filed matches with particular username. Scenario: cat testfor1 deekshi:x:7082:7082::/home/deekshi:/bin/bash harini1:x:7083:7083::/home/harini1:/bin/bash Here,if first field contains "deekshi", then i should replace... (4 Replies)
Discussion started by: Sumanthsv
4 Replies

2. Shell Programming and Scripting

Replace encrypted password in /etc/shadow using sed

Hello friends, We have encrypted password strings for all of our users (each user has different password). After creating users in Linux, we replace encrypted passwords manually on /etc/shadow so that their passwords directly work. Instead we want to do it using scripting. I tried with sed... (2 Replies)
Discussion started by: prvnrk
2 Replies

3. Shell Programming and Scripting

Replace a field with a character as per the field length

Hi all, I have a requirement to replace a field with a character as per the length of the field. Suppose i have a file where second field is of 20 character length. I want to replace second field with 20 stars (*). like ******************** As the field is not a fixed one, i want to do the... (2 Replies)
Discussion started by: gani_85
2 Replies

4. Shell Programming and Scripting

Script to bypass the password field

Hello all Im trying to write a script that can get past the "enter password" field.Coming to the details, Im planning to write a script that can actually check for the validity of certificates in websphere. There is a utility "keytool" that helps provide this information.However if we want to... (4 Replies)
Discussion started by: coolkid
4 Replies

5. Shell Programming and Scripting

sed to replace a field from a line with another field

i have something like this, cat filename.txt hui this si s"dfgdfg" omeone ipaddress="10.19.123.104" wel hope this works i want to replace only 10.19.123.104 with different ip say 10.19.123.103 i tried this sed -i "s/'ipaddress'/'ipaddress=10.19.123.103'/g" filename.txt ... (1 Reply)
Discussion started by: vivek d r
1 Replies

6. Shell Programming and Scripting

Replace line and field using SED and/or AWK or some other suggestion

QUESTION 1: How do you replace a specific line (i.e. line 4) with a new user defined line (i.e. the contents of SAMS’s name, history, math and English grades have been set already). I have been attempting to use SED (FYI: I don’t have GNU SED) or AWK, but haven’t had any luck. FYI: I am using... (1 Reply)
Discussion started by: thibodc
1 Replies

7. Shell Programming and Scripting

Replace specific field on specific line sed or awk

I'm trying to update a text file via sed/awk, after a lot of searching I still can't find a code snippet that I can get to work. Brief overview: I have user input a line to a variable, I then find a specific value in this line 10th field in this case. After asking for new input and doing some... (14 Replies)
Discussion started by: crownedzero
14 Replies

8. Shell Programming and Scripting

ftp:Password field is displayed

I am trying to get a file by doing ftp to the server. The below script works fine but as I type password it is displayed as simple text. HOST='192.108.245.101' echo 'username: ' read USER echo 'password:' read PASSWD ftp -n $HOST <<END_SCRIPT quote USER $USER quote PASS $PASSWD lcd... (1 Reply)
Discussion started by: hiten.r.chauhan
1 Replies

9. Shell Programming and Scripting

Trying to use sed to remove the value of one field from another field

I'm trying to use sed to remove the value of one field from another field. For example: cat inputfile 123|ABC|Generic_Textjoe@yahoo.com|joe@yahoo.com|DEF 456|GHI|Other_recordjohn@msn.com|john@msn.com|JKL 789|MNO|No_Email_On_This_One|smith@gmail.com|PQR I would like to remove the email... (2 Replies)
Discussion started by: bribri87
2 Replies

10. Shell Programming and Scripting

Is there a way to automatically prepopulate a password field?

I want to know if there is a way that I can right a script that will su to root and prepopulate the password field? (6 Replies)
Discussion started by: chrchcol
6 Replies
Login or Register to Ask a Question