david/sshbackup
david
/
sshbackup
Archived
1
0
Fork 0
This repository has been archived on 2023-12-23. You can view files and clone it, but cannot push or open issues or pull requests.
sshbackup/keymgmt.sh

60 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
# key management funcion
interactive()
{
tty -s
return $?
}
keymgmt()
{
local username=$(id -un)
local userid=$(id -u)
#find out where running users $HOME is
while read line; do
line=$(echo $line | sed 's/ //g')
line=$(echo $line | sed 's/:/ /g')
if [ $(echo $line | awk '{print $3}') -eq $userid ]; then
local home=$(echo $line | awk '{print $6}')
fi
done < /etc/passwd
if [ -z $1 ]; then
sshkeyfile="$home/.ssh/id_rsa"
else
sshkeyfile="$1"
fi
if [ -r $sshkeyfile ]; then
#ssh key found
:
else
if ( interactive ); then
echo "no ssh key found"
echo -e "do you want to create a ssh key pair? [y/n] \c"
read choice
if [ -z $choice ]; then
echo "aborting mission. no ssh key found."
exit 1
elif [ $choice == "y" ] || [ $choice == "Y" ]; then
#creating ssh key pair
ssh-keygen
fi
else
echo "aborting mission. no ssh key found."
exit 1
fi
fi
}
keymgmt
#end of file