Create new ssh key implicitly
This commit is contained in:
parent
e9e8e41bfa
commit
dd2ae9b720
1 changed files with 17 additions and 2 deletions
|
@ -16,21 +16,36 @@ function backupAction -V dir
|
|||
|
||||
if [ -z "$VALHALLA_BACKUP_DIR" ]
|
||||
if fish "$dir/../../../lib/modules/partition/confirm.fish" "Do you wish to store the backup on an SSH server?" n
|
||||
set -l keyVar VALHALLA_BACKUP_SERVER_KEY
|
||||
set -l keyPath ~root/.config/port-valhalla/valhalla
|
||||
read -xP "Please specify the host name of the SSH server: " VALHALLA_BACKUP_SERVER
|
||||
read -xP "Please specify the port of the SSH server (default 22): " VALHALLA_BACKUP_SERVER_PORT
|
||||
read -xP "Please specify the name of the user to log in to the SSH server: " VALHALLA_BACKUP_SERVER_USER
|
||||
read -xP "Please specify the path to the key file for logging in to the SSH server: " VALHALLA_BACKUP_SERVER_KEY
|
||||
set -l host "$VALHALLA_BACKUP_SERVER"
|
||||
|
||||
if [ -z "$$keyVar" ]
|
||||
set -gx "$keyVar" "$keyPath"
|
||||
sudo mkdir -p (dirname "$keyPath")
|
||||
sudo ssh-keygen -f "$$keyVar" -N ""
|
||||
end
|
||||
|
||||
if [ -z "$VALHALLA_BACKUP_SERVER_PORT" ]
|
||||
set -x VALHALLA_BACKUP_SERVER_PORT 22
|
||||
end
|
||||
|
||||
if [ -n "$VALHALLA_BACKUP_SERVER_USER" ]
|
||||
set host "$VALHALLA_BACKUP_SERVER_USER@$host"
|
||||
end
|
||||
|
||||
echo
|
||||
echo "$(tput setaf 3)==== WARNING ====$(tput sgr0)"
|
||||
echo "For a seamless experience, please make sure that you are able to establish an unattended ssh connection using key authentication."
|
||||
echo
|
||||
echo "Your public key is:"
|
||||
sudo cat "$VALHALLA_BACKUP_SERVER_KEY.pub"
|
||||
echo
|
||||
echo "$(tput bold)This command should succeed without user interaction:$(tput sgr0)"
|
||||
echo "sudo ssh -o PasswordAuthentication=no -i $(string escape -- "$VALHALLA_BACKUP_SERVER_KEY") -p $VALHALLA_BACKUP_SERVER_PORT $VALHALLA_BACKUP_SERVER true"
|
||||
echo "sudo ssh -o PasswordAuthentication=no -i $(string escape -- "$VALHALLA_BACKUP_SERVER_KEY") -p $VALHALLA_BACKUP_SERVER_PORT $host true"
|
||||
read -P "Press enter once you're done: "
|
||||
echo
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue