From 4e25639de4bfde96e29bc3291e13706bd0ece104 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 21 Nov 2016 19:08:33 -0700 Subject: [PATCH] Create the user's `authorized_keys` file if it does not exist Closes #2469 --- plugins/ssh-keys/functions | 5 +++++ plugins/ssh-keys/subcommands/add | 1 + 2 files changed, 6 insertions(+) diff --git a/plugins/ssh-keys/functions b/plugins/ssh-keys/functions index 24b5e6807..b6765691e 100755 --- a/plugins/ssh-keys/functions +++ b/plugins/ssh-keys/functions @@ -16,3 +16,8 @@ verify_ssh_key_exists() { declare desc="Test that public key exists" [[ -e ${DOKKU_ROOT}/.ssh/authorized_keys ]] || dokku_log_fail "No public keys found." } + +create_ssh_key_file() { + declare desc="Ensure the public key file exists" + touch "${DOKKU_ROOT}/.ssh/authorized_keys" +} diff --git a/plugins/ssh-keys/subcommands/add b/plugins/ssh-keys/subcommands/add index dac80e909..4424c3004 100755 --- a/plugins/ssh-keys/subcommands/add +++ b/plugins/ssh-keys/subcommands/add @@ -19,6 +19,7 @@ add_keys() { [[ -n "$name" && -n "$key_contents" ]] || dokku_log_fail "Two arguments are required if not piping, ie: dokku ssh-keys:add " local count="$(wc -l <<< "$key_contents")" [ "$count" -eq 1 ] || dokku_log_fail 'Too many keys provided, set one per invocation of dokku ssh-keys:add ' + create_ssh_key_file verify_ssh_key_exists echo "$key_contents" | sshcommand acl-add dokku "$name" || dokku_log_fail "sshcommand returned an error: $?" verify_ssh_key_file