What's new

Closed Delete all ssh user in a linux vps

Status
Not open for further replies.
Isang option pa, use the lock method rather than change shell method. Either way will work. Pero mas preferred ko ito.

Code:
while IFS=":" read -r users x uid x; do { [[ $uid -ge 1000 ]] && [[ $uid -lt 65534 ]]; } && usermod -L "$users"; done </etc/passwd
[/code
madadamay ba si nobody dito ?
 
Alternatively, pwede baguhin nalang login shell into /usr/sbin/nologin para ma-disable only instead of delete.

In-adjust ko ng konti yung one-liner: a) para hindi madamay sa modification yung 'nobody' account sa Debian which is quite an important account; b) greater than or equal to 1000 yung UID.

Code:
while IFS=":" read -r users x uid x; do { [[ $uid -ge 1000 ]] && [[ $uid -lt 65534 ]]; } && chsh -s /usr/sbin/nologin "$users"; done </etc/passwd
ou nga pla sir nakalimutan ko 65534 nga pla uid ng nobody

ty sa fix sir
 
ou nga pla sir nakalimutan ko 65534 nga pla uid ng nobody

ty sa fix sir
aayuun :) kaya pala. hhihi

boss may script ka dyan na delete expired users mismo sa database ?

ang alam ko yung script mo auto delete yung expired users.

example.
expired users : driver

create ako new account na same username which is driver
User already registered naka lagay kahit expire na.
 
aayuun :) kaya pala. hhihi

boss may script ka dyan na delete expired users mismo sa database ?

ang alam ko yung script mo auto delete yung expired users.

example.
expired users : driver

create ako new account na same username which is driver
User already registered naka lagay kahit expire na.
Try mo 'to. 3 lines yan. Copy-paste mo sa terminal one by one. May failsafe yan na ang made-delete lang yung expired accounts at hindi affected yung non-expired.

Code:
ACCOUNTS=( $(awk -F':' '$3>=1000 && $3<65534 { print $1; }' /etc/passwd) )
for i in ${ACCOUNTS[@]}; do FOR_DELETION+=( $(grep -f <(echo $i) /etc/shadow | grep -F '!' | cut -d':' -f1) ); done
for i in "${FOR_DELETION[@]}"; do echo "Deleting user: $i ..."; userdel -rf $i; done
 
keep sharing lods
 
Try mo 'to. 3 lines yan. Copy-paste mo sa terminal one by one. May failsafe yan na ang made-delete lang yung expired accounts at hindi affected yung non-expired.

Code:
ACCOUNTS=( $(awk -F':' '$3>=1000 && $3<65534 { print $1; }' /etc/passwd) )
for i in ${ACCOUNTS[@]}; do FOR_DELETION+=( $(grep -f <(echo $i) /etc/shadow | grep -F '!' | cut -d':' -f1) ); done
for i in "${FOR_DELETION[@]}"; do echo "Deleting user: $i ..."; userdel -rf $i; done
try ko to.boss :)
maraming salamat :*
 
Try mo 'to. 3 lines yan. Copy-paste mo sa terminal one by one. May failsafe yan na ang made-delete lang yung expired accounts at hindi affected yung non-expired.

Code:
ACCOUNTS=( $(awk -F':' '$3>=1000 && $3<65534 { print $1; }' /etc/passwd) )
for i in ${ACCOUNTS[@]}; do FOR_DELETION+=( $(grep -f <(echo $i) /etc/shadow | grep -F '!' | cut -d':' -f1) ); done
for i in "${FOR_DELETION[@]}"; do echo "Deleting user: $i ..."; userdel -rf $i; done

after ko i run and ikatlo
for i in "${FOR_DELETION[@]}"; do echo "Deleting user: $i ..."; userdel -rf $i; done

ito error boss
Deleting user: Debian-exim ...
userdel: Debian-exim mail spool (/var/mail/Debian-exim) not found
 
giphy.gif
 

Attachments

Status
Not open for further replies.
Back
Top