#! /bin/bash # Execute this script to add a new user to the cluster globally echo ' ' echo 'Existing users in /etc/passwd of '$HOSTNAME cat /etc/passwd | awk -F":" '{print $1, $3}' | awk '{if($2>=1000 && $2<4000) {print}}' | sort echo ' ' read -p "Enter new username : " username /share/apps/local/bin/coc-sshreachable hosts=$(cat /share/tmp/ssh-reachable.dat) no=$(cat /share/apps/configrepo/users_data/userpass.latest.dat | awk '{print $1}' | sort -n | awk 'END {print}' | awk '{print $1+1}') rm -rf luid.dat for rn in $hosts do ssh -oStrictHostKeyChecking=no $rn "/export/share/apps/local/bin/coc-uid" >> luid.dat done uid=$(cat luid.dat | awk '{print $6}' | sort | uniq | awk 'END {print}') #echo last userid from all nodes is $userid rm -rf luid.dat uid=$(( $uid + 1 )) #echo 'uid='$uid will be assigned passwd=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 9 | head -n 1) #echo $no $username $uid $passwd echo $no $username $uid $passwd >>/share/apps/configrepo/users_data/userpass.latest.dat #echo $no $username $uid $passwd have been appended to /share/apps/configrepo/users_data/userpass.latest.dat for rn in $hosts do command='useradd -u '"$uid"' -g users -p $(echo '"$passwd"' | openssl passwd -1 -stdin) '"$username" echo 'adding user '"$username"' in '"$rn" echo $command pdsh -R ssh -w "$rn" $command done chmod -R 755 /home/"$username" echo $username with uid $uid and passord $passwd have been added to the cluster ### su - $username -c "ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -N '' " su - $username -c "cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys"