Created
March 6, 2018 09:59
-
-
Save SuoXC/fbb0533b622e0ef442a87646af08bd68 to your computer and use it in GitHub Desktop.
add an user on all nodes in a cluster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 在所有机器上配置部署账号和权限 | |
set -x | |
ROOT_PASS=rootpassword | |
USR=dev | |
PASS=password | |
OTHER_NODES_IP="ip1 ip2" #以空格分割 | |
#read ROOT_PASS | |
#read USR | |
#read PASS | |
useradd $USR | |
echo "$USR:$PASS" | chpasswd | |
cat /dev/zero |sudo -u $USR ssh-keygen -q -N '' | |
echo "$USR ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/${USR//-/_} | |
chown -R $USR:$USR /data | |
for node in $OTHER_NODES_IP ; do | |
sshpass -p$ROOT_PASS ssh root@$node "useradd $USR; echo '$USR:$PASS' | chpasswd"; | |
sshpass -p$ROOT_PASS ssh root@$node "echo '$USR ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/${USR//-/_}" | |
sudo -u $USR sshpass -p$PASS ssh-copy-id -o StrictHostKeyChecking=no $USR@$node | |
sshpass -p$ROOT_PASS ssh root@$node "chown -R $USR:$USR /data" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment