1

I have authenticated a server using authorized_keys push so I could run command ssh 192.168.1.101 from my system and could connect via server.

Now, I tried with library , It didn't worked for me

  Net::SSH.start("192.168.1.209",username) do |ssh|   @output=ssh.exec!("ls -l")  end

as, This required username field. I want without username.

So , I tried this

    system('ssh 192.168.1.209 "ls -l"') 

It run the command for me. But I want the output in a variable like @output in first example. Is there any command any gem or any way by which I could get the solution ?

1
  • also, I would need to run 5-10 commands in a request.. Commented Feb 24, 2012 at 15:48

3 Answers 3

1

Any ssh connection requires a username. The default is either your system account name or whatever's specified in .ssh/config for that host you're connecting to.

Your current username should be set as ENV['USER'] if you need to access that.

If you're curious what username is being used for that connection, try finding out with ssh -v which is the verbose mode that explains what's going on.

Sign up to request clarification or add additional context in comments.

3 Comments

actually in shell prompt, I am able to run ssh 192.168.1.209 it connect without asking username because I copied keys and added into authorized_keys .
The username is always required even with the authorized keys, because the key doesn't necessarily tell the server which user is logging in. Likely that ssh is getting your username from the OS or config file
Exactly, you can connect without it asking for a username, but that doesn't mean it isn't using a username
0

you can pass parameters into %x[] as follows:

1. dom = ‘www.ruby-rails.in‘
2. @whois = %x[whois #\{dom\}]

Comments

0

Backquotes works very similar to "system" function but with important difference. Shell command enclosed between the backquotes is executed with standard output as result.

So, following statement should execute ssh 192.168.1.209 "ls -l" and puts directory files listing into @output variable:

@output = `ssh 192.168.1.209 "ls -l"`

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.