Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am writing a program to disable users from a system, i want to replace /bin/bash to /bin/false.

Example

xxx:x:1:22:xx:/export/home/xx:**/bin/bash**

replace to

xxx:x:1:22:xx:/export/home/xx:**/bin/false**

I want do with using bash script.

I know one way to do this is using sed. But i am not good at regular expressions.

Can any one help?

share|improve this question

migrated from stackoverflow.com Feb 27 '13 at 20:02

This question came from our site for professional and enthusiast programmers.

    
mv /bin/bash /tmp/bin/false –  Stepo Feb 27 '13 at 17:07
4  
@Stepo That just makes /bin/bash unavailable to everyone. –  chepner Feb 27 '13 at 17:08
    
ah gosh, I see. you're right! –  Stepo Feb 27 '13 at 17:10

1 Answer 1

up vote 4 down vote accepted

Well you don't do it at all with sed or regular expressions. What you do is to use the program chsh to change the shell of a user.

chsh -s /bin/false username

alternatively:

usermod -s /bin/false username

If you wanted to replace it with an actual shell you'd also have to make sure that it is listed in /etc/shells.

share|improve this answer
    
chsh says command not found!! i am using solaris –  user1212207 Feb 27 '13 at 17:13
    
@user1212207: on my SunOS 5.8 SUNW,UltraAX-i2 ther is a usermod. And it even supports -s. I stand by my answer. –  0xC0000022L Feb 27 '13 at 17:24
    
yeah usermod works fine!!! and solved my problem –  user1212207 Feb 27 '13 at 17:36
    
Thanks for the help –  user1212207 Feb 27 '13 at 17:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.