Shell script to add a public key to server and provide sudo privillege for that user.
#!/bin/bash #function which contains the ssh public key for user admin to add in the servers and another function to check if key already exists #If you want to add your user key, replace the admin with your username and add your ssh key to the section shown below. ################################################################## admin_keyexist_check() { if grep -q "******ssh key goes here******admin@<serverhostname>" /home/admin/.ssh/authorized_keys; then echo " The ssh key already exists and is shown below...!!" grep -i "admin" /home/admin/.ssh/authorized_keys echo "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" echo "Removing this shell script now...!!" rm -fv $0 exit else echo " The ssh key doesn't exists...!! We will add it...!!" echo "++++++++++++++++++++++++++++++++++...