开发者

Net-SSH Ruby Authentication

开发者 https://www.devze.com 2023-03-31 11:04 出处:网络
Can someone please shed some light on this issue I have with net-ssh. I am new to ruby and am working on this project.

Can someone please shed some light on this issue I have with net-ssh. I am new to ruby and am working on this project.

How do I tell net ssh to use the username and password provided to connect to the servers without needing to 开发者_如何学编程have a shared key between my machine and those servers?

def connect
  Net::SSH.start("#{@servername}", "#{username}", :password => "#{password}") do |ssh|
    result = ssh.exec!("ls #{@dirname}").chomp
    puts result
  end #ssh
end


It's not clear really what you're asking here. You appear to be using the Net::SSH api correctly, at least according to its docs.

One concern is your use of "#{@servername}" which is a redundant use of variable interpolation. There's no need for any of the quotes around servername, username or password.

However, please be clearer about your problem. Are you asking how you can pass these values in to your script, or is there a problem with Net::SSH accepting them?

0

精彩评论

暂无评论...
验证码 换一张
取 消