0

I am building a script to automate and minimize access to root. I am going to try do it via SSH. I am currently having an issue using sed to replace UID and GID 0 shell to /sbin/nologin.

Why am I doing this? This disables root on login, gdm, kdm, su, ssh, scp, sftp. I am trying to execute root privilege only via sudo. If you know any suggestion on minimizing root access, please also suggest.

This is the current issue:

grep :0:0: /etc/passwd | sudo sed 's_/bin/bash_/sbin/nologin_' /etc/passwd

What is currently doing is replacing all /bin/bash to /sbin/nologin.

1
  • have you tried usermod --expiredate 1 root ? This should disable the root account. Jan 29, 2015 at 7:42

2 Answers 2

2

1. get a acount which is a sudoer

su -
echo '<YOU>  ALL=(ALL:ALL)  ALL'>>/etc/sudoers
exit

2. disable the root account

sudo usermod --expiredate 1 root

3. test it

$ su -
Password: <correct password>
Your account is expired.

Tested on Debian GNU/Linux

0

what

grep :0:0: /etc/passwd | sudo sed 's_/bin/bash_/sbin/nologin_' /etc/passwd

do ?

  • grep :0:0: /etc/passwd search for line(s ?) with uid/gid being 0, this usualy give the line with root, this line is feeded to STDOUT (standard output )
  • | output from grep is feed to sudo sed which is discarded due to a file being specified in command line.
  • sed 's_/bin/bash_/sbin/nologin_' /etc/passwd this replace bash by nologin from /etc/passwd to STDOUT, /etc/passwd is left unchanged.

have you simply try .. ?

sudo sed -i '/:0:0:/s_/bin/bash_/sbin/nologin_' /etc/passwd

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .