简体   繁体   English

Net-SSH Ruby身份验证

[英]Net-SSH Ruby Authentication

Can someone please shed some light on this issue I have with net-ssh. 有人可以告诉我有关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? 如何告诉net ssh使用提供的用户名和密码来连接服务器,而无需在我的机器和这些服务器之间使用共享密钥?

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 . 至少根据其docs ,您似乎正确使用了Net :: SSH api。

One concern is your use of "#{@servername}" which is a redundant use of variable interpolation. 一个问题是您使用"#{@servername}" ,这是变量插值的多余用法。 There's no need for any of the quotes around servername , username or password . 不需要在servernameusernamepassword周围加上任何引号。

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? 您是在问如何将这些值传递到脚本中,还是Net :: SSH接受它们时出现问题?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM