Skip to content

Instantly share code, notes, and snippets.

@rrreeeyyy
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rrreeeyyy/83c6657d8bfa7186136a to your computer and use it in GitHub Desktop.
Save rrreeeyyy/83c6657d8bfa7186136a to your computer and use it in GitHub Desktop.
serverspec-sshkey-passphrase
require 'serverspec'
require 'pathname'
require 'net/ssh'
require 'highline/import'
include Serverspec::Helper::Ssh
include Serverspec::Helper::DetectOS
RSpec.configure do |c|
if ENV['ASK_SUDO_PASSWORD']
c.sudo_password = ask("Enter sudo password: ") { |q| q.echo = false }
else
c.sudo_password = ENV['SUDO_PASSWORD']
end
c.host = host
options = Net::SSH::Config.for(c.host)
if ENV['ASK_KEY_PASSPHRASE']
options[:passphrase] = ask("\nEnter passphrase for key: ") { |q| q.echo = false }
else
options[:passphrase] = ENV['KEY_PASSPHRASE']
end
user = options[:user] || Etc.getlogin
c.ssh = Net::SSH.start(c.host, user, options)
end
@rrreeeyyy
Copy link
Author

ssh-agent 使うのがどうしても嫌な人向け

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment