Mercurial > hg > beaglert
changeset 364:ab6d78e18e85 prerelease
Simplified setup-ssh files: no more need for keypairs, now just setting the bbb entry in ~/.ssh/config
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Thu, 09 Jun 2016 01:47:13 +0100 |
parents | 6e428d6b57ef |
children | e70f023e0f7f |
files | scripts/setup-ssh-windows.sh scripts/setup-ssh.sh scripts/setup_ssh.sh |
diffstat | 3 files changed, 13 insertions(+), 174 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/setup-ssh-windows.sh Thu Jun 09 01:25:32 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +0,0 @@ -#!/bin/bash -IP_ADDRESS="192.168.7.2" -PRIVATE_KEY_FILENAME=$HOME/.ssh/id_rsa #if you change this to something like bbb_rsa it will be safer when cleaning but if you don't have the config file you will have to - # ssh -i $HOME/.ssh/bbb_rsa root@192.168.7.2 - # in order to log in -CONFIG_FILENAME=$HOME/.ssh/config -CLEAN=0 -if [ $# -gt 0 ]; then - while (( "$#" )); do - if [ $1 = "-k" ]; then - if [[ $2 == "/"* ]]; then - #it's full path - PRIVATE_KEY_FILENAME=$2 - else - #assume it's a key in .ssh - PRIVATE_KEY_FILENAME=$HOME'/.ssh/'$2 - fi - shift - shift - continue - fi - if [ $1 = "-i" ]; then - IP_ADDRESS=$2 - shift - shift - continue - fi - if [ $1 = "clean" ] ; then - CLEAN=1 - shift - continue - fi - #if we get here, then a wrong number or type of parameters have been passed - echo "Generates a key pair (if does not exist) and copies it over to the host, saving the settings in the /.ssh/config file - Usage: - -i [ipAddress] sets the host to authenticate to (default: 192.168.7.1) - -k [filename] sets the key file to use for autentication - (default: ~/.ssh/id_rsa)" - exit 1; - done; -fi - -if [ $CLEAN -eq 1 ] ; then - printf "Cleaning ${PRIVATE_KEY_FILENAME}, ${PRIVATE_KEY_FILENAME}.pub, ${CONFIG_FILENAME} and bbb:~/.ssh/ . Are you sure? This might prevent you from accessing other services that use the same key or config files (y/n) " - read sure - if [ $sure = "y" ] ; then - ssh root@192.168.7.2 rm -rf .ssh &&\ - rm $PRIVATE_KEY_FILENAME ${PRIVATE_KEY_FILENAME}.pub $CONFIG_FILENAME - if [ $? -ne 0 ] ; then - printf "ERROR: error while cleaning" - exit 4 - fi - printf "Cleaning succesful" - exit 0 - fi -fi -printf Pinging the Beaglebone on $IP_ADDRESS -ping $IP_ADDRESS -w 1000 -n 1 &>/dev/null #returns 1 if ping is unsuccesful -if [ $? -ne 0 ] ; then # $? is the return value of the last command - echo "Error: the Beaglebone is not alive, make sure it is connected and drivers are installed (MacOs and Windows only) or try again later" ; - exit 1 -fi; -printf "...done\n" - -mkdir -p $HOME/.ssh # create the ssh folder if it does not exist -printf '\nHost bbb\nHostname '$IP_ADDRESS'\nUser root\nIdentityFile '$PRIVATE_KEY_FILENAME'\n' >> $HOME/.ssh/config - -printf "Generating key $PRIVATE_KEY_FILENAME if it does not exist" -ls $PRIVATE_KEY_FILENAME &>/dev/null || ssh-keygen -t rsa -f $PRIVATE_KEY_FILENAME -q -P "" # the command after || will be executed only if the previous command fails (i.e. if id_rsa does not exist) -if [ $? -ne 0 ] ; then - printf "\nERROR: an error occurred while creating key pair $PRIVATE_KEY_FILENAME\n" - exit 2 -fi -printf "...Done\n" - -printf "Type 'a' (without quotes) when prompted for a password: \n" - -# StrictHostKeyChecking=no below will prevent the following message upon the first connection: -# "The authenticity of host '192.168.1.2' can't be established." -# which would require the user to type 'yes' -cat ${PRIVATE_KEY_FILENAME}.pub | (ssh -q -o StrictHostKeyChecking=no bbb 'mkdir -p .ssh; cat > .ssh/authorized_keys') -if [ $? -ne 0 ] ; then - printf "ERROR: An error occurred while copying the public key to the BBB\n" - exit 3 -fi -printf "SSH setup complete. You can now ssh into the beaglebone with command: ssh bbb\n" -exit 0
--- a/scripts/setup-ssh.sh Thu Jun 09 01:25:32 2016 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +0,0 @@ -#!/bin/bash -IP_ADDRESS="192.168.7.2" -PRIVATE_KEY_FILENAME=$HOME/.ssh/id_rsa #if you change this to something like bbb_rsa it will be safer when cleaning but if you don't have the config file you will have to - # ssh -i $HOME/.ssh/bbb_rsa root@192.168.7.2 - # in order to log in -CONFIG_FILENAME=$HOME/.ssh/config -CLEAN=0 -if [ $# -gt 0 ]; then - while (( "$#" )); do - if [ $1 = "-k" ]; then - if [[ $2 == "/"* ]]; then - #it's full path - PRIVATE_KEY_FILENAME=$2 - else - #assume it's a key in .ssh - PRIVATE_KEY_FILENAME=$HOME'/.ssh/'$2 - fi - shift - shift - continue - fi - if [ $1 = "-i" ]; then - IP_ADDRESS=$2 - shift - shift - continue - fi - if [ $1 = "clean" ] ; then - CLEAN=1 - shift - continue - fi - #if we get here, then a wrong number or type of parameters have been passed - echo "Generates a key pair (if does not exist) and copies it over to the host, saving the settings in the /.ssh/config file - Usage: - -i [ipAddress] sets the host to authenticate to (default: 192.168.7.1) - -k [filename] sets the key file to use for autentication - (default: ~/.ssh/id_rsa)" - exit 1; - done; -fi - -if [ $CLEAN -eq 1 ] ; then - printf "Cleaning ${PRIVATE_KEY_FILENAME}, ${PRIVATE_KEY_FILENAME}.pub, ${CONFIG_FILENAME} and bbb:~/.ssh/ . Are you sure? This might prevent you from accessing other services that use the same key or config files (y/n) " - read sure - if [ $sure = "y" ] ; then - ssh root@192.168.7.2 rm -rf .ssh &&\ - rm $PRIVATE_KEY_FILENAME ${PRIVATE_KEY_FILENAME}.pub $CONFIG_FILENAME - if [ $? -ne 0 ] ; then - printf "ERROR: error while cleaning" - exit 4 - fi - printf "Cleaning succesful" - exit 0 - fi -fi -#printf "Pinging the Beaglebone on $IP_ADDRESS\n" -#ping $IP_ADDRESS -w 1000 -c &>/dev/null 1 #returns 1 if ping is unsuccesful -#if [ $? -ne 0 ] ; then # $? is the return value of the last command -# echo "Error: the Beaglebone is not alive, make sure it is connected and drivers are installed (MacOs and Windows only) or try again later" ; -# exit 1 -#fi; -#printf "...done\n" - -mkdir -p $HOME/.ssh # create the ssh folder if it does not exist -printf '\nHost bbb\nHostname '$IP_ADDRESS'\nUser root\nIdentityFile '$PRIVATE_KEY_FILENAME'\n' >> $HOME/.ssh/config - -printf "Generating key $PRIVATE_KEY_FILENAME if it does not exist" -ls $PRIVATE_KEY_FILENAME &>/dev/null || ssh-keygen -t rsa -f $PRIVATE_KEY_FILENAME -q -P "" # the command after || will be executed only if the previous command fails (i.e. if id_rsa does not exist) -if [ $? -ne 0 ] ; then - printf "\nERROR: an error occurred while creating key pair $PRIVATE_KEY_FILENAME\n" - exit 2 -fi -printf "...Done\n" - -printf "Type 'a' (without quotes) when prompted for a password: \n" - -# StrictHostKeyChecking=no below will prevent the following message upon the first connection: -# "The authenticity of host '192.168.1.2' can't be established." -# which would require the user to type 'yes' -cat ${PRIVATE_KEY_FILENAME}.pub | (ssh -q -o StrictHostKeyChecking=no bbb 'mkdir -p .ssh; cat >> .ssh/authorized_keys') -if [ $? -ne 0 ] ; then - printf "ERROR: An error occurred while copying the public key to the BBB\n" - exit 3 -fi -printf "SSH setup complete. You can now ssh into the beaglebone with command: ssh bbb\n" -exit 0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/setup_ssh.sh Thu Jun 09 01:47:13 2016 +0100 @@ -0,0 +1,13 @@ +#!/bin/bash +[ -z "$BBB_HOSTNAME" ] && BBB_HOSTNAME="192.168.7.2" +[ -z "$BBB_USER" ] && BBB_USER="root" +[ -z "$BBB_HOST" ] && BBB_HOST="bbb" +CONFIG_FILENAME=$HOME/.ssh/config +mkdir -p $HOME/.ssh # create the ssh folder if it does not exist +printf "\nHost $BBB_HOST\nHostname $BBB_HOSTNAME\nUser $BBB_USER\nStrictHostKeyChecking=no\n\n" >> $HOME/.ssh/config +if [ $? -eq 0 ]; +then + printf "You can now login into the Beaglebone with\n\$ ssh $BBB_HOST\n" +else + printf "Something went wrong. You should still be able to log into the BeagleBone with \n\$ ssh $BBB_USER@$BBB_HOSTNAME\n" +fi