From 702d81860af98f99043ecd604969e67d98fd5b00 Mon Sep 17 00:00:00 2001 From: MatthewLi Date: Mon, 7 Dec 2015 22:40:33 -0800 Subject: ssh login passwordless script JIRA: BOTTLENECK-32 Change-Id: I8dca120b3efe55b493b94ac77f95788212eedbc1 Signed-off-by: MatthewLi --- .../passwordless_SSH/set_passwordless_ssh.sh | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 utils/infra_setup/passwordless_SSH/set_passwordless_ssh.sh (limited to 'utils/infra_setup/passwordless_SSH/set_passwordless_ssh.sh') diff --git a/utils/infra_setup/passwordless_SSH/set_passwordless_ssh.sh b/utils/infra_setup/passwordless_SSH/set_passwordless_ssh.sh new file mode 100755 index 00000000..cbca6b20 --- /dev/null +++ b/utils/infra_setup/passwordless_SSH/set_passwordless_ssh.sh @@ -0,0 +1,52 @@ +#! /bin/bash + +#this script is copied from https://github.com/guioconnor/Passwordless-SSH. +#the Bottlenecks project needs to set the machines login each other passwordless, this script is appropriate. + +filename="id_rsa" +path="$HOME/.ssh" + +if [ $1 ] +then + hostname=$1 + if [ $2 ] + then + username=$2 + else + username="$USER" + fi +else + # Read the host and username to store public key (the host/username accepting passwordless ssh from this computer) + echo "What host you want to grant passwordless SSH from this computer?" + read hostname + echo "What is your username on $hostname? ($USER?)" + read username + + if [ ! $username ] + then + username="$USER" + fi +fi + + +# Generate rsa files +if [ -f $path/$filename ] +then + echo "RSA key exists on $path/$filename, using existing file" +else + ssh-keygen -t rsa -f "$path/$filename" + echo RSA key pair generated +fi + +echo "We need to log into $hostname as $username to set up your public key (hopefully last time you'll use password from this computer)" +cat "$path/$filename.pub" | ssh "$hostname" -l "$username" '[ -d .ssh ] || mkdir .ssh; cat >> .ssh/authorized_keys; chmod 700 ~/.ssh; chmod 600 ~/.ssh/authorized_keys' +status=$? + +if [ $status -eq 0 ] +then + echo "Set up complete, try to ssh to $host now" + exit 0 +else + echo "an error has occured" + exit 255 +fi -- cgit 1.2.3-korg