SSH login without password

article #356, updated 492 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.

echo "setup-autossh by Jonathan E. Brickman,"
if [ $# = 0 ]; then
	read -p "Please enter the SSH destination in the format user@host : " sshdest
elif [ $# = 1 ]; then
	echo "Usage: setup-autossh [user@destination]"
	exit 1
if [ ! -f ~/.ssh/id_rsa ]; then
	echo "Creating RSA key for authorization..."
	ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa
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/ | ssh $sshdest $remotecmd

Categories:   Remote Access, RDP and Others   Tools