SSH login without password

article #356, updated 460 days ago

Here’s a bash script! Works very nicely. Once run on one side and specifying a destination, one does not need a password to open that SSH link in the future.

#!/bin/bash
echo "setup-autossh by Jonathan E. Brickman, jeb@ponderworthy.com"
if [ $# = 0 ]; then
	read -p "Please enter the SSH destination in the format user@host : " sshdest
elif [ $# = 1 ]; then
	sshdest=$1
else
	echo "Usage: setup-autossh [user@destination]"
	exit 1
fi
if [ ! -f ~/.ssh/id_rsa ]; then
	echo "Creating RSA key for authorization..."
	ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
fi
echo "Copying authorized RSA key to $sshdest ..."
remotecmd="cat > authorized_keys ; mkdir -p .ssh ; cat authorized_keys >> .ssh/authorized_keys ; rm authorized_keys"
cat ~/.ssh/id_rsa.pub | ssh $sshdest $remotecmd

Categories:   Remote Access, RDP and Others   Tools