Skip to content

Commit a6f24a0

Browse files
committed
Make cached known hosts lookup the default
1 parent 9714a2b commit a6f24a0

3 files changed

Lines changed: 8 additions & 15 deletions

File tree

README.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -508,19 +508,6 @@ pooling behaviour entirely by setting the idle_timeout to zero:
508508
SSHKit::Backend::Netssh.pool.idle_timeout = 0 # disabled
509509
```
510510

511-
## Known hosts caching
512-
513-
If you connect to many hosts with the `Netssh` backend, looking up `~/.ssh/known_hosts` can significantly impact performances.
514-
You can mitigate this by using SSHKit's lookup caching like this:
515-
516-
```ruby
517-
SSHKit::Backend::Netssh.configure do |ssh|
518-
ssh.ssh_options = {
519-
known_hosts: SSHKit::Backend::Netssh::KnownHosts.new,
520-
}
521-
end
522-
```
523-
524511
## Tunneling and other related SSH themes
525512

526513
In order to do special gymnasitcs with SSH, tunneling, aliasing, complex options, etc with SSHKit it is possible to use [the underlying Net::SSH API](https://github.com/capistrano/sshkit/blob/master/EXAMPLES.md#setting-global-ssh-options) however in many cases it is preferred to use the system SSH configuration file at [`~/.ssh/config`](http://man.cx/ssh_config). This allows you to have personal configuration tied to your machine that does not have to be committed with the repository. If this is not suitable (everyone on the team needs a proxy command, or some special aliasing) a file in the same format can be placed in the project directory at `~/yourproject/.ssh/config`, this will be merged with the system settings in `~/.ssh/config`, and with any configuration specified in [`SSHKit::Backend::Netssh.config.ssh_options`](https://github.com/capistrano/sshkit/blob/master/lib/sshkit/backends/netssh.rb#L133).

lib/sshkit/backends/netssh.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,13 @@ class Configuration
155155
attr_writer :ssh_options
156156

157157
def ssh_options
158-
@ssh_options ||= {}
158+
default_options.merge(@ssh_options ||= {})
159+
end
160+
161+
private
162+
163+
def default_options
164+
@default_options ||= {known_hosts: SSHKit::Backend::Netssh::KnownHosts.new}
159165
end
160166
end
161167

test/unit/backends/test_netssh.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_net_ssh_configuration_options
2626
assert_equal %w(/home/user/.ssh/id_rsa), backend.config.ssh_options[:keys]
2727
assert_equal false, backend.config.ssh_options[:forward_agent]
2828
assert_equal %w(publickey password), backend.config.ssh_options[:auth_methods]
29-
29+
assert_instance_of backend::KnownHosts, backend.config.ssh_options[:known_hosts]
3030
end
3131

3232
def test_netssh_ext

0 commit comments

Comments
 (0)