Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

System shell nologin script required

Shell Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 09-14-2017   -   Original Discussion by Gamma
Gamma's Unix or Linux Image
Gamma Gamma is offline
Registered User
 
Join Date: Sep 2017
Last Activity: 1 November 2017, 12:12 PM EDT
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
System shell nologin script required

Hi

Part of our security audit we found that following system account's had shells configured;



Code:
sync
 halt
 shutdown

I believe this can be achieved by following commands:


Code:
chsh -s /sbin/nologin (user)



Code:
usermod -s /sbin/nologin (user)

However, I would like simple script to include these 3 account's only. Please can you advise on a simple script which can set this shell to nologin for these 3 users?

Regards
G


Moderator's Comments:
System shell nologin script required Please use CODE tags as required by forum rules!

Last edited by RudiC; 09-14-2017 at 12:05 PM.. Reason: Added CODE tags.
Sponsored Links
    #2  
Old Unix and Linux 09-14-2017   -   Original Discussion by Gamma
RudiC's Unix or Linux Image
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 18 January 2018, 12:47 PM EST
Location: Aachen, Germany
Posts: 11,951
Thanks: 353
Thanked 3,686 Times in 3,384 Posts
Welcome to the forum.

Why a script for this one-off task?
Sponsored Links
    #3  
Old Unix and Linux 09-14-2017   -   Original Discussion by Gamma
Aia's Unix or Linux Image
Aia Aia is offline
Registered User
 
Join Date: May 2008
Last Activity: 20 November 2017, 9:27 AM EST
Posts: 1,673
Thanks: 49
Thanked 641 Times in 601 Posts
Please, try the following:


Code:
for u in sync halt shutdown; do
    usermod -s /sbin/nologin "$u"
done

    #4  
Old Unix and Linux 09-14-2017   -   Original Discussion by Gamma
Gamma's Unix or Linux Image
Gamma Gamma is offline
Registered User
 
Join Date: Sep 2017
Last Activity: 1 November 2017, 12:12 PM EDT
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Hi

Yes it's a small one off task But it appears they are reluctant for having a script to do the work rather than a manual approach.

Therefore, wanted a script to do resolve the issue of having invalid shell accounts for the three accounts mentioned earlier.

Thanks,
G

Last edited by Gamma; 09-14-2017 at 01:28 PM.. Reason: Need to add more information
Sponsored Links
    #5  
Old Unix and Linux 09-14-2017   -   Original Discussion by Gamma
rbatte1's Unix or Linux Image
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 18 January 2018, 10:38 AM EST
Location: Lancashire, UK
Posts: 3,438
Thanks: 1,493
Thanked 671 Times in 604 Posts
You could probably use /bin/false if /sbin/nologin does not exist.
Sponsored Links
    #6  
Old Unix and Linux 09-14-2017   -   Original Discussion by Gamma
Gamma's Unix or Linux Image
Gamma Gamma is offline
Registered User
 
Join Date: Sep 2017
Last Activity: 1 November 2017, 12:12 PM EDT
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
[QUOTE=Gamma;303003499]Hi

Yes it's a small one off task But it appears they are reluctant for having a script to do the work rather than a manual approach.

Therefore, wanted a script to do resolve the issue of having invalid shell accounts for the three accounts mentioned earlier.

The other thing I forgot to add was do we need to define the "/etc/passwd" within your for loop or will that be captured?

Thanks,
Linux
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
shell script required... venkatesht Shell Programming and Scripting 3 01-13-2009 06:00 AM
Shell script help required max29583 Shell Programming and Scripting 2 07-16-2008 07:28 AM
shell script required sethunath Linux 1 07-07-2007 06:04 AM
aix nologin shell zuessh AIX 5 12-16-2006 11:59 AM
nologin shell on Solaris? GKnight Solaris 2 09-22-2006 05:09 PM



All times are GMT -4. The time now is 01:48 PM.