Shell Script for SSH Without Password in Linux/RHEL/Centos/Ubuntu

#Script for passwordless authentication for remote host 
#Author: explinux
echo "enter ip : "
read ip
echo "enter user"
read user
ssh $user@$ip mkdir -p .ssh
cat .ssh/ | ssh $user@$ip 'cat >> .ssh/authorized_keys'
ssh $user@$ip "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"
ssh $user@$ip

How to use the script: 

use vi editor and create a file with .sh extension 
# vi 
copy and paste the above script and save it.
change permission 
#chmod u+x 
run script 
# ./ 


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top