Merge pull request #3 from iamshital/master

Added scripts to enable root user
This commit is contained in:
Shital Savekar 2018-05-16 21:18:04 -07:00 коммит произвёл GitHub
Родитель afde792af5 4b9a469018
Коммит 4692422c5b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 65 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,25 @@
#!/bin/bash
#AUTHOR : SHITAL SAVEKAR <v-shisav@microsoft.com>
#Description : Enables passwordless authentication for root user.
#How to use : ./enablePasswordLessRoot.sh
#In multi VM cluster. Execute this script in one VM. It will create a sshFix.tar
#Copy this sshFix.tar to other VMs (/root) in your cluster and execute same script. It will extract previously created keys.
#This way, all VMs will have same public and private keys in .ssh folder.
rm -rf /root/.ssh
cd /root
keyTarFile=sshFix.tar
if [ -e ${keyTarFile} ]; then
echo | ssh-keygen -N ''
rm -rf .ssh/*
tar -xvf ${keyTarFile}
echo "KEY_COPIED_SUCCESSFULLY"
else
echo | ssh-keygen -N ''
cat /root/.ssh/id_rsa.pub > /root/.ssh/authorized_keys
echo "Host *" > /root/.ssh/config
echo "StrictHostKeyChecking no" >> /root/.ssh/config
rm -rf /root/.ssh/known_hosts
cd /root/ && tar -cvf sshFix.tar .ssh/*
echo "KEY_GENERATED_SUCCESSFULLY"
fi

Просмотреть файл

@ -0,0 +1,40 @@
#!/bin/bash
#AUTHOR : SHITAL SAVEKAR <v-shisav@microsoft.com>
#Description : Enables root user and sets password. Needs to run with sudo permissions.
#How to use : ./enableRoot.sh -password <new_root_password>
while echo $1 | grep ^- > /dev/null; do
eval $( echo $1 | sed 's/-//g' | tr -d '\012')=$2
shift
shift
done
password=$password
sshd_configFilePath="/etc/ssh/sshd_config"
sshdServiceName="sshd"
usermod --password $(echo $password | openssl passwd -1 -stdin) root
if [ $? == 0 ]; then
sed -i 's/.*PermitRootLogin.*/PermitRootLogin yes/g' $sshd_configFilePath
if [ $? == 0 ]; then
echo "$sshd_configFilePath verifed for root login."
echo "ROOT_PASSWRD_SET"
service $sshdServiceName restart || systemctl restart sshd.service
sshdServiceStatus=$?
if [ $sshdServiceStatus != 0 ]; then
service ssh restart
sshdServiceStatus=$?
fi
else
echo "$sshd_configFilePath verification failed for root login."
echo "ROOT_PASSWORD_SET_SSHD_CONFIG_FAIL"
fi
else
echo "Unable to set root password."
echo "ROOT_PASSWORD_NOT_SET"
fi
if [ $sshdServiceStatus == 0 ]; then
echo "SSHD_RESTART_SUCCESSFUL"
else
echo "SSHD_RESTART_FAIL"
fi
exit 0