Skip to content

Instantly share code, notes, and snippets.

@ipepe
Last active September 2, 2018 16:43
Show Gist options
  • Save ipepe/e587fc1f98e1c0cb049a185fe86715b9 to your computer and use it in GitHub Desktop.
Save ipepe/e587fc1f98e1c0cb049a185fe86715b9 to your computer and use it in GitHub Desktop.
Add my id_rsa.pub to authorized_keys in Capistrano
task :add_my_key_to_authorized_keys do
unless `cat "$HOME/.ssh/id_rsa.pub"`.empty?
id_rsa_pub_path = `echo "$HOME/.ssh/id_rsa.pub"`.strip
on roles(:all) do
upload! id_rsa_pub_path, "/tmp/id_rsa.pub"
execute 'cat /tmp/id_rsa.pub .ssh/authorized_keys | sort -u -o .ssh/authorized_keys'
execute 'cat .ssh/authorized_keys'
end
end
end
before :starting, :add_my_key_to_authorized_keys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment