Skip to content

Instantly share code, notes, and snippets.

@scarybot
Last active September 19, 2019 07:42
Show Gist options
  • Save scarybot/1dda918cacffa9594396f3a6862b4f0c to your computer and use it in GitHub Desktop.
Save scarybot/1dda918cacffa9594396f3a6862b4f0c to your computer and use it in GitHub Desktop.
Get a list of allowed SSH auth methods (for Ryan)
require 'net/ssh'
transport_session = Net::SSH::Transport::Session.new('ryans-server.com')
transport_session.send_message(transport_session.service_request("ssh-userauth"))
auth_session = Net::SSH::Authentication::Session.new(transport_session)
auth_session.expect_message(Net::SSH::Transport::Constants::SERVICE_ACCEPT)
transport_session.send_message(Net::SSH::Authentication::Methods::Publickey.new(transport_session).userauth_request(false, false, false))
allowed_auth_methods = transport_session.next_message.instance_variable_get('@named_elements')[:authentications].split(',')
puts allowed_auth_methods.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment