Before using this script install except
In fedora it is installed by executing the command yum install except.
Copy the below part in any text editor, save is as file_name.sh and
execute it using ./file_name.sh
#!/bin/sh
#Author Sunayan Saikia. Free to use but must keep the Author's name
#Setting Password-less ssh in a multi node cluster script
#Reference: @wangrui, http://www.linuxforums.org/forum/programming-scripting/24126-ssh-username-password-script.html
stty -echo;
read -p "Input password:" A;
stty echo;
echo;
ssh-keygen -t dsa -P "" -f /root/.ssh/id_dsa
cat /root/.ssh/id_dsa.pub >> /root/.ssh/authorized_keys
chmod go-w /root/ /root/.ssh
chmod 600 /root/.ssh/authorized_keys
chown root /root/.ssh/authorized_keys
for SLAVE in {192.168.1.1,192.168.1.2};do
#modifying /etc/ssh/sshd_config
echo "Connecting to $SLAVE ";
echo "$SLAVE: Part-1 *********";
echo "Modifying the /etc/ssh/sshd_config file...";
expect -c "set timeout -1;\
spawn ssh -o StrictHostKeyChecking=no $SLAVE -l root \"sed -i 's/#PermitRootLogin yes/PermitRootLogin yes/g' /etc/ssh/sshd_config;sed -i 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/g' /etc/ssh/sshd_config;sed -i 's/#PermitEmptyPasswords no/PermitEmptyPasswords yes/g' /etc/ssh/sshd_config;\";\
match_max 100000;\
expect *password:*;\
send -- $A\r;\
interact;";
#copying the master public key to the slave
echo "$SLAVE: Part-2 *********";
echo "Copying the master public key...";
expect -c "set timeout -1;\
spawn scp /root/.ssh/id_dsa.pub root@$SLAVE:/root/.ssh/master.pub;\
match_max 100000;\
expect *password:*;\
send -- $A\r;\
interact;";
#setting required permissions
echo "$SLAVE: Part-3 *********";
echo "Setting required permissions..";
expect -c "set timeout -1;\
spawn ssh $SLAVE -l root \"
ssh-keygen -R '$SLAVE | cut -d \" \" -f 4';cat /root/.ssh/master.pub >> /root/.ssh/authorized_keys;chmod go-w /root/ /root/.ssh;chmod 600 /root/.ssh/authorized_keys;chown root /root/.ssh/authorized_keys\";\
match_max 100000;\
expect *password:*;\
send -- $A\r;\
interact;";
echo "Finished job on $SLAVE ***********";
done
In fedora it is installed by executing the command yum install except.
Copy the below part in any text editor, save is as file_name.sh and
execute it using ./file_name.sh
#!/bin/sh
#Author Sunayan Saikia. Free to use but must keep the Author's name
#Setting Password-less ssh in a multi node cluster script
#Reference: @wangrui, http://www.linuxforums.org/forum/programming-scripting/24126-ssh-username-password-script.html
stty -echo;
read -p "Input password:" A;
stty echo;
echo;
ssh-keygen -t dsa -P "" -f /root/.ssh/id_dsa
cat /root/.ssh/id_dsa.pub >> /root/.ssh/authorized_keys
chmod go-w /root/ /root/.ssh
chmod 600 /root/.ssh/authorized_keys
chown root /root/.ssh/authorized_keys
for SLAVE in {192.168.1.1,192.168.1.2};do
#modifying /etc/ssh/sshd_config
echo "Connecting to $SLAVE ";
echo "$SLAVE: Part-1 *********";
echo "Modifying the /etc/ssh/sshd_config file...";
expect -c "set timeout -1;\
spawn ssh -o StrictHostKeyChecking=no $SLAVE -l root \"sed -i 's/#PermitRootLogin yes/PermitRootLogin yes/g' /etc/ssh/sshd_config;sed -i 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/g' /etc/ssh/sshd_config;sed -i 's/#PermitEmptyPasswords no/PermitEmptyPasswords yes/g' /etc/ssh/sshd_config;\";\
match_max 100000;\
expect *password:*;\
send -- $A\r;\
interact;";
#copying the master public key to the slave
echo "$SLAVE: Part-2 *********";
echo "Copying the master public key...";
expect -c "set timeout -1;\
spawn scp /root/.ssh/id_dsa.pub root@$SLAVE:/root/.ssh/master.pub;\
match_max 100000;\
expect *password:*;\
send -- $A\r;\
interact;";
#setting required permissions
echo "$SLAVE: Part-3 *********";
echo "Setting required permissions..";
expect -c "set timeout -1;\
spawn ssh $SLAVE -l root \"
ssh-keygen -R '$SLAVE | cut -d \" \" -f 4';cat /root/.ssh/master.pub >> /root/.ssh/authorized_keys;chmod go-w /root/ /root/.ssh;chmod 600 /root/.ssh/authorized_keys;chown root /root/.ssh/authorized_keys\";\
match_max 100000;\
expect *password:*;\
send -- $A\r;\
interact;";
echo "Finished job on $SLAVE ***********";
done
No comments:
Post a Comment