diff --git a/Testscripts/Linux/enablePasswordLessRoot.sh b/Testscripts/Linux/enablePasswordLessRoot.sh new file mode 100644 index 000000000..17fc865b4 --- /dev/null +++ b/Testscripts/Linux/enablePasswordLessRoot.sh @@ -0,0 +1,25 @@ +#!/bin/bash +#AUTHOR : SHITAL SAVEKAR +#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 diff --git a/Testscripts/Linux/enableRoot.sh b/Testscripts/Linux/enableRoot.sh new file mode 100644 index 000000000..aefb9e135 --- /dev/null +++ b/Testscripts/Linux/enableRoot.sh @@ -0,0 +1,40 @@ +#!/bin/bash +#AUTHOR : SHITAL SAVEKAR +#Description : Enables root user and sets password. Needs to run with sudo permissions. +#How to use : ./enableRoot.sh -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