Search code examples
rubyruby-on-rails-3shellcommand-line-argumentsnet-ssh

SSH connection with Ruby without username using `authorized_keys`


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 ?


Solution

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

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