Tag Info

Hot answers tagged

4

getent group somegroupname || groupadd somegroupname


2

Since no input example is given, I'm going to assume a very basic patern: Uesrs groups a p,r,t b p,q In that case you have several options, because usermod -G can use the second column natively. something like while read line do usermod -G "$(cut -f2 -d" ")" $(cut -f1 -d" ") done < users.txt The while loop reads each line from users.txt, and ...


2

If you use a custom shell as suggested by Arcege and 2bc, then that shell will receive the command which the user intends to execute as an argument because the shell is invoked like this: shellname -c the_original_command So ignore the -c (that your $1) and find the command in $2. For example: #!/bin/sh case "$2" in on) do something ...


2

passwd -l <user> doesn't stop all possible means of logging in. For example, if they log in using ssh with public keys they can still login as they won't need a password. To stop the user logging in again, edit the /etc/passwd file and remove the user or change the 7th column to /sbin/nologin. Run: ps -u <user> to see what process the ...


1

passwd -l <user> does not disable the account.as gareth said the user may still can login using another authentication token such as SSH key. to disable this account you should use usermod --expiredate 1 this set the account expire date to 1970. Now you should kill all processes the user is started. running: $pgrep -u Foo will print all processes ...


1

First grep all the 'test' user's process and kill -9 all pid's then delete the user. pgrep -u test ps -fp $(pgrep -u test) killall -KILL -u test userdel -r test


1

Have you tried killing all the user's processes with the SIGKILL? pkill -KILL -u username


1

id -u somegroupname &>/dev/null || groupadd somegroupname since id -u somegroupname will return non-zero if it doesn't exist.


1

The best and simplest approach would be to parse a file with the required information as suggested by @DannyG. While that's the way I would do it myself, another would be to hardcode the user/groups combinations in your script. For example: #!/usr/bin/env bash ## Set up an indexed array where the user is the key ## and the groups the values. declare -A ...


1

Given your comments, you can just statically build the script with the groups hard-written in it. This script expect a list of users, one user per line, on the standard input. So call it with ./script < users.txt for example. #!/bin/bash groups="p q r" # the list of all groups you want your users in # the following function is a case statement # it ...



Only top voted, non community-wiki answers of a minimum length are eligible