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 1 Week Ago
Gamma Gamma is offline
Registered User
 
Join Date: Sep 2017
Last Activity: 15 September 2017, 4:48 AM EDT
Posts: 3
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; 1 Week Ago at 11:05 AM.. Reason: Added CODE tags.
Sponsored Links
    #2  
Old Unix and Linux 1 Week Ago
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 25 September 2017, 8:39 AM EDT
Location: Aachen, Germany
Posts: 11,374
Thanks: 299
Thanked 3,527 Times in 3,244 Posts
Welcome to the forum.

Why a script for this one-off task?
Sponsored Links
    #3  
Old Unix and Linux 1 Week Ago
Aia's Unix or Linux Image
Aia Aia is offline
Registered User
 
Join Date: May 2008
Last Activity: 14 September 2017, 11:33 AM EDT
Posts: 1,641
Thanks: 46
Thanked 625 Times in 586 Posts
Please, try the following:

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

    #4  
Old Unix and Linux 1 Week Ago
Gamma Gamma is offline
Registered User
 
Join Date: Sep 2017
Last Activity: 15 September 2017, 4:48 AM EDT
Posts: 3
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; 1 Week Ago at 12:28 PM.. Reason: Need to add more information
Sponsored Links
    #5  
Old Unix and Linux 1 Week Ago
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 25 September 2017, 8:55 AM EDT
Location: Lancashire, UK
Posts: 3,261
Thanks: 1,391
Thanked 630 Times in 569 Posts
You could probably use /bin/false if /sbin/nologin does not exist.
Sponsored Links
    #6  
Old Unix and Linux 1 Week Ago
Gamma Gamma is offline
Registered User
 
Join Date: Sep 2017
Last Activity: 15 September 2017, 4:48 AM EDT
Posts: 3
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 05:00 AM
Shell script help required max29583 Shell Programming and Scripting 2 07-16-2008 06:28 AM
shell script required sethunath Linux 1 07-07-2007 05:04 AM
aix nologin shell zuessh AIX 5 12-16-2006 10:59 AM
nologin shell on Solaris? GKnight Solaris 2 09-22-2006 04:09 PM



All times are GMT -4. The time now is 09:30 AM.