CERN

Sysmes

So, I’ve added the sysmes-user to the entire cluster, added it’s pubkey-information, disabled password-login, added the sysmes-user to the /etc/sudoers file, etc.

#!/bin/bash
 
for host in $(cat hosts); do
	if ping -c1 -w1 $host|grep -qi "bytes from"; then
		ssh $host "\
			skill -KILL -u sysmes; \
			if grep -qi '^sysmes' /etc/passwd; then \
				usermod -u 901 sysmes; \
			else \
				useradd -m -d /opt/sysmes -g 100 -s /bin/bash -u 901 sysmes; \
			fi; \
			if [ ! -d /opt/sysmes/.ssh/ ]; then \
				mkdir /opt/sysmes/.ssh; \
			fi; \
			chown -R sysmes:users /opt/sysmes; \
			passwd -l sysmes; \
			if ! dpkg --list|grep -qi 'ii  sudo '; then \
				apt-get install --force-yes -y sudo; \
			fi; \
			if ! grep -qi '^sysmes' /etc/sudoers; then \
                        	printf '\n# Sudo for sysmes-user\nsysmes ALL = NOPASSWD: ALL\n\n' >> /etc/sudoers; \
                        fi;"
		scp /opt/sysmes/.ssh/authorized_keys $host:/opt/sysmes/.ssh/authorized_keys
	fi
done