Permalink
Browse files

Added support for specifying ssh option in the shell command.

The options are appended to the saved ones.
  • Loading branch information...
1 parent 2005080 commit df3dc129c7aacc9c093f4aa92a4ab4d39a0f5c1d @babysnakes committed May 1, 2011
Showing with 49 additions and 5 deletions.
  1. +6 −2 README.rdoc
  2. +4 −0 features/run_shell.feature
  3. +11 −2 lib/runsshlib/cli.rb
  4. +28 −1 spec/runsshlib/cli_spec.rb
View
@@ -102,9 +102,13 @@ This program is distributed under the GPL v2 license.
line must be specified manually (probably from the error message in the
previous command), and currently we only deal with <code>~/.ssh/known_hosts</code>
file.
+* Added ssh options support. These could be specified when saving or when
+ running shell. As an _unsafe_ shortcut, there is an option to connect
+ to a host without verifying the key. This is mainly useful for local
+ virtual machines, or similar occasion where security is not an issue.
* Implemented copying public key to remote host's authorized_keys file (via
ssh-copy-id).
-* Changed behavior upon prompt cancelation (in _delete_ and _import_) - It now
+* Changed behavior upon prompt cancellation (in _delete_ and _import_) - It now
aborts execution instead of exit 0.
* Some code refactoring (CLI class).
* CLI Tests refactorings:
@@ -130,5 +134,5 @@ This program is distributed under the GPL v2 license.
proper warnings. ✓
* ssh-copy-id capabilities. ✓
* Add the ability to add ssh options to bookmark + shortcut for ignoring ssh
- known hosts file (should issue a warning when using this shortcut).
+ known hosts file (should issue a warning when using this shortcut).
* Go over documentation and make sure they're up to date.
@@ -56,6 +56,10 @@ Feature: Connect to other hosts by ssh
| -n other.host | ssh -l mylogin other.host |
| -l otherlogin | ssh -l otherlogin some.host |
+ Scenarios: Adding ssh options
+ | all_arguments | command |
+ | -o ForwardAgent=true | ssh -l mylogin some.host -o ForwardAgent=true |
+
Scenarios: Remote command pseudo terminal and quoting (e.g., to avoid wrong parsing of '&')
| all_arguments | command |
| -- ls | ssh -t -l mylogin some.host -- \"ls\" |
View
@@ -195,6 +195,9 @@ def parse_shell(args)
'(effective only with remote command)', :short => :T
opt :insecure_host_key, 'delete the specified line form known hosts ' \
'file. EXPERIMENTAL and DANGEROUS!', :type => :int, :short => :I
+ opt :option, 'ssh option. appended to saved ssh options. ' \
+ 'can be used more then once.',
+ :short => :o, :type => :string, :multi => true
stop_on "--"
end
# handle the case of remote command (indicated by --)
@@ -271,7 +274,8 @@ def parse_add_update(cmd, args)
:type => :string
opt :local_tunnel, "Tunnel definition (see description above)",
:short => :L, :type => :string
- opt :option, 'Ssh option (corresponds to ssh -o <option>)',
+ opt :option, 'Ssh option (corresponds to ssh -o <option>). ' \
+ 'Can be used multiple times.',
:short => :o, :multi => true, :type => :string
opt :no_host_key_checking, "DANGEROUS! Don't verify host key when " \
"connecting to this host. Shortcut for '-o UserKnownHostsFile=" \
@@ -354,7 +358,12 @@ def run_shell(path)
# currently this is all we need. We may need to make it better
# later.
definition = host.definition.merge(@options) do |key, this, other|
- other ? other : this
+ case key
+ when :option
+ this + other
+ else
+ other ? other : this
+ end
end
SshBackend.shell(definition)
end
@@ -139,6 +139,33 @@
cli.run
end
+ it "merges given options with saved ones" do
+ stub_ssh_exec
+
+ # multiple options saved, single option given
+ RunSSHLib::CLI.new(%W(-f #{TMP_FILE} add one two -n some.host -N)).run
+ capture(:stdout) do
+ RunSSHLib::CLI.new(%W(-f #{TMP_FILE} shell one two -o ForwardAgent=true)).run
+ end
+ @buf.should include('ssh some.host')
+ @buf.should include('StrictHostKeyChecking=no')
+ @buf.should include('UserKnownHostsFile=/dev/null')
+ @buf.should include('ForwardAgent=true')
+
+ # single option saved, multiple options given
+ RunSSHLib::CLI.new(%W(-f #{TMP_FILE} add one three -n some.host
+ -o ForwardAgent=true)).run
+ capture(:stdout) do
+ RunSSHLib::CLI.new(%W(-f #{TMP_FILE} shell one three
+ -o StrictHostKeyChecking=no
+ -o UserKnownHostsFile=/dev/null)).run
+ end
+ @buf.should include('ssh some.host')
+ @buf.should include('StrictHostKeyChecking=no')
+ @buf.should include('UserKnownHostsFile=/dev/null')
+ @buf.should include('ForwardAgent=true')
+ end
+
context "insecure-host-key" do
let (:cli) {
RunSSHLib::CLI.new(%W(-f #{TMP_FILE} shell --insecure-host-key 1 some host))
@@ -157,7 +184,7 @@
it "warns the user about deleting conflicting key" do
capture(:stderr) do # avoid stderr
capture(:stdout, input) do |variable|
- # Since were canceliing it should exit with error but we don't
+ # Since were cancelling it should exit with error but we don't
# test that now
expect { cli.run }.to exit_abnormaly
end

0 comments on commit df3dc12

Please sign in to comment.