Ruby Net: SSH Control Master?

I currently have a Ruby (Rails) application that needs to make many short SSH connections. This works great using the Ruby Net :: SSH library, except that the application must log in and negotiate keys every time I want to make a command that is too slow.

Is there a way to enable Control Master with Ruby Net :: SSH? When testing on the command line, this makes logins (after the first) very fast, since the connection is already open (keys are agreed, etc.).

If there is no way to do this using Net :: SSH, can anyone suggest an alternative library that could do this?

I assume this should be a general requirement, so hopefully someone can help.

Thanks!

+4
source share
2 answers

Why not just open the connection? Ssh calls are dummy since I don't know api, but it serves its purpose:

def ssh_execute(user, command) Thread.current[:user_connections] ||= {} unless Thread.current[:user_connections][user.id] Thread.current[:user_connections][user.id] = Net::SSH.connect(...) end ssh = Thread.current[:user_connections][user.id] ssh.run_command(command) end 

You will receive one ssh connection for each thread, or if your application is deployed with a passenger, each process will have one connection and will reuse it.

Is this what you want?

+5
source

You can specify exactly which encryption protocol you want to minimize shaking hands, but okay, yes, SSH can be a little slow if you need to scale it.

In fact, an interesting activity is http://saltstack.org/ , it has implemented its own alternative "ssh" on top of 0mq, which makes it super-fast to run parallel commands on multiple servers, apparently without the same problems. related to ssh, e.g. chef, etc. Maybe you could build salt, do it?

+2
source

Source: https://habr.com/ru/post/1390022/


All Articles