#!/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:
Related Article : ssh Without Password in Linux 2020.html
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