Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 546337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:51:23+00:00 2026-05-13T10:51:23+00:00

I am trying to run a script in several machines I have at work,

  • 0

I am trying to run a script in several machines I have at work, to gather some information about them, such as which OS they’re running, what services run on them, some configurations, etc. I have a machine on which I log before ssh-ing to any of the other machines, because of the public key setup it has. From there, I can ssh into all of the other machines without being asked for my password.

What I want to do is to automate logging onto all of these machines from that one, but the script is running on my local machine. So I just learned about ruby-ssh-gateway and am trying that, but I can’t seem to get pubkey authentication to work.

I do something like this:

gateway = Net::SSH::Gateway.new('gatewaymachine', 'username', :password => 'password')
all_machines.each do |machine|
  gateway.ssh(machine, 'username') do |ssh|
    uname = ssh.exec!('uname -a')
    puts "machine: #{machine}; OS: #{uname}"
  end
end

But I get a Net::SSH::AuthenticationFailed exception.

If, instead, I provide the password, like so:

gateway.ssh(machine, 'username', :password => 'password')

it does work, but that’s not viable, since passwords are not the same across machines.

Does anyone know how I can make this work?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:51:24+00:00Added an answer on May 13, 2026 at 10:51 am

    Are the machines you are talking to behind a NAT firewall? If not, you don’t need ruby-ssh-gateway.

    Have you created a public key on the origin box, for the user which runs the program, and given that key to the target user on each target box?

    $ ssh-keygen -t dsa    # Only do this once
    $ ssh-copy-id -i ~/.ssh/id_dsa.pub user@machine
    (enter the password)
    

    and to make sure the key is working:

    $ ssh user@machine      # should not ask for a password
    

    Once you’ve done that, it’s as simple as using system or backtick to shell out to ssh:

    system('ssh machine "ls -l"')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a shell script that, when run, will set some environment
I am trying to run a script, which is intense(that is lot of loops
I'm trying to run a script from the Windows XP console. (In case it's
I'm trying to run some queries to get rid of XSS in our database
I have a .NET project that's always been built/run by/on 32 bit machines. I
i'm trying to write a script which would process certain files. The data are
I was trying to run a script to create a DB with all the
The script I am trying to run via shell_exec in PHP requires an environmental
I'm trying to run a script that uses an ANT build but I don't
I'm trying to run Python scripts using Xcode's User Scripts menu. The issue I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.