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

#!/bin/bash
#Script for passwordless authentication for remote host 
#Author: explinux
#Date:19june2020
echo "enter ip : "
read ip
echo "enter user"
read user
ssh $user@$ip mkdir -p .ssh
cat .ssh/id_rsa.pub | 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 passwordless.sh 
copy and paste the above script and save it.
change permission 
#chmod u+x passwordless.sh 
run script 
# ./passwordless.sh 

Done

Leave a Comment

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