ssh-locate 0.0.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +35 -0
- data/.travis.yml +4 -0
- data/Gemfile +5 -2
- data/README.md +55 -6
- data/Rakefile +7 -0
- data/features/agent-ids.feature +24 -4
- data/features/step_definitions/agent-ids.rb +12 -3
- data/lib/net/ssh/locate/version.rb +2 -1
- data/lib/net/ssh/locate.rb +91 -17
- metadata +32 -23
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 784e22cc6152ba4f53793125ac7c02f1ce31601aa839578fa293efdd7e7a7acc
|
4
|
+
data.tar.gz: ab574c8e2d68d9b7259ce0ec9c893cda059b8582bee7af4151210e6130482f5b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f22628c4de53289d4cc1ebe340150f249f78186667e266b12a70ddaab46ee2bd72868554c40441c539de3de0cfbdb5df708a558290291cb7f6ba7887d2aac16c
|
7
|
+
data.tar.gz: c279c4578506b0aae500f9914c3642b1a61d1bf6ffcc0bbcf8f86edec8a1160545d35ae353254c07a4dfbb0cfbb2cc5c505eeba94f9d666f5ba7765c4ea067a1
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ master ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ master ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
strategy:
|
21
|
+
matrix:
|
22
|
+
ruby-version: ['2.6', '2.7', '3.0']
|
23
|
+
|
24
|
+
steps:
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
- name: Set up Ruby
|
27
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
28
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
29
|
+
# uses: ruby/setup-ruby@v1
|
30
|
+
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
31
|
+
with:
|
32
|
+
ruby-version: ${{ matrix.ruby-version }}
|
33
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
34
|
+
- name: Run tests
|
35
|
+
run: bundle exec rake
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
-
source "
|
1
|
+
source "https://rubygems.org"
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
5
|
group :dev do
|
6
|
+
gem "rake"
|
6
7
|
gem "guard"
|
7
8
|
gem "rb-inotify"
|
8
9
|
gem "libnotify"
|
9
10
|
gem "cucumber"
|
10
|
-
gem "aruba"
|
11
|
+
gem "aruba"
|
11
12
|
gem "guard-cucumber"
|
13
|
+
gem "rspec-expectations"
|
14
|
+
gem "solargraph"
|
12
15
|
end
|
13
16
|
|
data/README.md
CHANGED
@@ -1,18 +1,45 @@
|
|
1
1
|
ssh-locate
|
2
2
|
==========
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
[![Build Status](https://secure.travis-ci.org/ameuret/ssh-locate.png)](http://travis-ci.org/ameuret/ssh-locate)
|
4
|
+
![Gem](https://img.shields.io/gem/dt/ssh-locate?label=RubygemsDL&logo=ruby&logoColor=red)
|
5
|
+
|
6
|
+
A command line tool that helps you locate and contact a SSH agent launched in a separate shell.
|
7
|
+
|
8
|
+
|
9
|
+
### Wait, what ⁉️
|
10
|
+
|
11
|
+
This tool fills a gap in the OpenSSH suite of tools.
|
12
|
+
|
13
|
+
* No way of knowing the PID of a running SSH Agent
|
14
|
+
* No way of knowing the authentication socket of a running SSH Agent
|
15
|
+
* `ssh-agent` only supports Bourne and C shells
|
16
|
+
|
6
17
|
Features
|
7
18
|
--------
|
8
19
|
- output is fully compatible with openSSH:
|
9
20
|
|
10
|
-
```
|
21
|
+
``` bash
|
11
22
|
SSH_AUTH_SOCK=/tmp/ssh-locate-test.15970; export SSH_AUTH_SOCK;
|
12
23
|
SSH_AGENT_PID=12427; export SSH_AGENT_PID;
|
13
24
|
echo Agent pid 12427;
|
14
25
|
```
|
26
|
+
|
27
|
+
- supports the Fish shell
|
28
|
+
|
29
|
+
``` fish
|
30
|
+
set -x SSH_AUTH_SOCK ssh-agent -a /tmp/zed
|
31
|
+
set -x SSH_AGENT_PID 1517651
|
32
|
+
```
|
33
|
+
|
34
|
+
(See also Fish Startup below)
|
35
|
+
|
36
|
+
- shows EMACS Lisp to activate agent:
|
15
37
|
|
38
|
+
``` emacs-lisp
|
39
|
+
(setenv "SSH_AUTH_SOCK" "/tmp/zed")
|
40
|
+
(setenv "SSH_AGENT_PID" "3216002")
|
41
|
+
```
|
42
|
+
|
16
43
|
Installation
|
17
44
|
------------
|
18
45
|
|
@@ -25,10 +52,32 @@ Launch your SSH agent and tell it to use a specific socket file with the -a opti
|
|
25
52
|
|
26
53
|
ssh-agent -a /tmp/deployer-38us9f
|
27
54
|
|
28
|
-
In a later shell (or any process running for the user
|
55
|
+
In a later shell (or any process running for the user who owns the agent):
|
56
|
+
|
57
|
+
### Bash
|
29
58
|
|
30
|
-
$ eval ssh-locate
|
59
|
+
$ eval `ssh-locate`
|
31
60
|
Agent pid 13457
|
61
|
+
|
62
|
+
### Fish
|
63
|
+
|
64
|
+
> ssh-locate | source
|
65
|
+
|
66
|
+
### EMACS
|
67
|
+
|
68
|
+
Using the `--emacs` option will output the lisp code to set the necessary environment variables in EMACS.
|
69
|
+
Just paste this anywhere (in a scratch buffer for example) and execute `eval-last-sexp` (usually bound to C-x C-e)
|
70
|
+
with the cursor positionned at the end of each line.
|
71
|
+
|
72
|
+
ssh-locate --emacs
|
73
|
+
|
74
|
+
Fish startup
|
75
|
+
------------
|
76
|
+
|
77
|
+
You can launch and activate an agent at startup by adding this to your config.fish:
|
78
|
+
|
79
|
+
ssh-agent -a /tmp/arnaud
|
80
|
+
ssh-locate | source
|
32
81
|
|
33
82
|
Caveat
|
34
83
|
------
|
data/Rakefile
CHANGED
data/features/agent-ids.feature
CHANGED
@@ -5,6 +5,7 @@ Feature: Agent IDs
|
|
5
5
|
|
6
6
|
Scenario: Locate a running agent
|
7
7
|
Given an ssh agent has been launched without parameters
|
8
|
+
Given the user's shell is Bash
|
8
9
|
When I run `ssh-locate`
|
9
10
|
Then the output should contain "SSH_AUTH_SOCK="
|
10
11
|
And the output should contain "export SSH_AUTH_SOCK;"
|
@@ -13,13 +14,15 @@ Feature: Agent IDs
|
|
13
14
|
And the output should contain the correct agent PID
|
14
15
|
And the output should contain the correct agent socket
|
15
16
|
|
16
|
-
Scenario: No agent is running or
|
17
|
+
Scenario: No agent is running or locatable
|
17
18
|
Given no agent is running
|
18
19
|
When I run `ssh-locate`
|
19
20
|
Then the output should be empty
|
20
21
|
|
21
|
-
|
22
|
+
@focus
|
23
|
+
Scenario: Locate an agent that shows its socket in the command line
|
22
24
|
Given an ssh agent has been launched with a specific socket
|
25
|
+
Given the user's shell is Bash
|
23
26
|
When I run `ssh-locate`
|
24
27
|
Then the output should contain "SSH_AUTH_SOCK="
|
25
28
|
And the output should contain "export SSH_AUTH_SOCK;"
|
@@ -27,7 +30,7 @@ Feature: Agent IDs
|
|
27
30
|
And the output should contain "export SSH_AGENT_PID;"
|
28
31
|
And the output should contain the correct agent PID
|
29
32
|
And the output should contain the correct agent socket
|
30
|
-
|
33
|
+
|
31
34
|
Scenario: Recognize and honor the agent managed by Ubuntu
|
32
35
|
Given an ssh agent has been launched in my Ubuntu session
|
33
36
|
When I run `ssh-locate`
|
@@ -37,9 +40,26 @@ Feature: Agent IDs
|
|
37
40
|
And the output should contain "export SSH_AGENT_PID;"
|
38
41
|
And the output should contain the correct agent PID
|
39
42
|
And the output should contain the correct agent socket
|
40
|
-
|
43
|
+
|
41
44
|
Scenario: Ignore agents run by someone else
|
42
45
|
Given an ssh agent is running for another user
|
43
46
|
And no ssh agent is running for me
|
44
47
|
When I run `ssh-locate`
|
45
48
|
Then the output should contain "no agent found"
|
49
|
+
|
50
|
+
Scenario: Support Fish
|
51
|
+
Given an ssh agent has been launched with a specific socket
|
52
|
+
Given the user's shell is Fish
|
53
|
+
When I run `ssh-locate`
|
54
|
+
Then the output should contain "set -x SSH_AUTH_SOCK"
|
55
|
+
And the output should contain "set -x SSH_AGENT_PID"
|
56
|
+
And the output should contain the correct agent PID
|
57
|
+
And the output should contain the correct agent socket
|
58
|
+
|
59
|
+
Scenario: Support EMACS
|
60
|
+
Given an ssh agent has been launched with a specific socket
|
61
|
+
When I run `ssh-locate --emacs`
|
62
|
+
Then the output should contain "(setenv \"SSH_AUTH_SOCK"
|
63
|
+
And the output should contain "(setenv \"SSH_AGENT_PID"
|
64
|
+
And the output should contain the correct agent PID
|
65
|
+
And the output should contain the correct agent socket
|
@@ -29,13 +29,22 @@ Given /^no ssh agent is running for me$/ do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
Then /^the output should be empty$/ do
|
32
|
-
|
32
|
+
expect(all_output).to be_empty
|
33
33
|
end
|
34
34
|
|
35
35
|
Then /^the output should contain the correct agent PID$/ do
|
36
|
-
|
36
|
+
expect(all_output).to include @agentPID.to_s
|
37
37
|
end
|
38
38
|
|
39
39
|
Then /^the output should contain the correct agent socket$/ do
|
40
|
-
|
40
|
+
expect(all_output).to include @agentSocket.to_s
|
41
41
|
end
|
42
|
+
|
43
|
+
Given("the user's shell is Fish") do
|
44
|
+
set_environment_variable('SHELL', 'fish')
|
45
|
+
end
|
46
|
+
|
47
|
+
Given("the user's shell is Bash") do
|
48
|
+
set_environment_variable('SHELL', 'bash')
|
49
|
+
end
|
50
|
+
|
data/lib/net/ssh/locate.rb
CHANGED
@@ -1,35 +1,109 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'net/ssh/locate/version'
|
2
|
+
require 'thor/group'
|
3
|
+
require 'sys/proctable'
|
4
|
+
require 'English'
|
4
5
|
|
5
6
|
module Net
|
6
7
|
module SSH
|
7
8
|
module Locate
|
8
9
|
class App < Thor::Group
|
9
10
|
include Thor::Actions
|
10
|
-
|
11
|
+
def self.banner
|
12
|
+
<<-LONGDESC
|
13
|
+
ssh-locate will search for a running ssh-agent and output the environment
|
14
|
+
variables needed to contact it.
|
15
|
+
|
16
|
+
To make sure that you're selecting the agent you launched and not the agent
|
17
|
+
launched by your Desktop Environment, you must use the -a option to specify
|
18
|
+
a socket path:
|
19
|
+
|
20
|
+
$ ssh-agent -a /tmp/zed
|
21
|
+
SSH_AUTH_SOCK=/tmp/zed; export SSH_AUTH_SOCK;
|
22
|
+
SSH_AGENT_PID=1908155; export SSH_AGENT_PID;
|
23
|
+
echo Agent pid 1908155;
|
24
|
+
|
25
|
+
Then later in another shell instance:
|
26
|
+
|
27
|
+
$ ssh-locate
|
28
|
+
SSH_AUTH_SOCK=/tmp/zed; export SSH_AUTH_SOCK;
|
29
|
+
SSH_AGENT_PID=1908155; export SSH_AGENT_PID;
|
30
|
+
echo Agent pid 1908155;
|
31
|
+
LONGDESC
|
32
|
+
end
|
33
|
+
|
34
|
+
class_option :emacs, type: :boolean, desc: 'Output EMACS LISP to execute in EMACS'
|
35
|
+
|
11
36
|
def locate_agent
|
12
|
-
|
37
|
+
@scanner = Scanner.new
|
38
|
+
@scanner.scan
|
39
|
+
end
|
40
|
+
|
41
|
+
def print_shell_commands
|
42
|
+
return unless @scanner.found?
|
43
|
+
|
44
|
+
if options[:emacs]
|
45
|
+
emacsOutput
|
46
|
+
elsif usingFish?
|
47
|
+
fishOutput
|
48
|
+
else
|
49
|
+
bashOutput
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def usingFish?
|
56
|
+
# TODO: This is far from perfect. Launching a secondary shell e.g. zsh from fish would
|
57
|
+
# still show the SHELL env var as /usr/bin/fish
|
58
|
+
ENV['SHELL'] =~ /fish/
|
59
|
+
end
|
60
|
+
|
61
|
+
def bashOutput
|
62
|
+
print "SSH_AUTH_SOCK=#{@scanner.agentSocket};"
|
63
|
+
puts "export SSH_AUTH_SOCK;"
|
64
|
+
print "SSH_AGENT_PID=#{@scanner.agentPID};"
|
65
|
+
puts "export SSH_AGENT_PID;"
|
66
|
+
puts "echo Agent pid #{@scanner.agentPID};"
|
67
|
+
end
|
68
|
+
|
69
|
+
def fishOutput
|
70
|
+
puts "set -x SSH_AUTH_SOCK #{@scanner.agentSocket}"
|
71
|
+
puts "set -x SSH_AGENT_PID #{@scanner.agentPID}"
|
72
|
+
end
|
73
|
+
|
74
|
+
def emacsOutput
|
75
|
+
puts "(setenv \"SSH_AUTH_SOCK\" \"#{@scanner.agentSocket}\")"
|
76
|
+
puts "(setenv \"SSH_AGENT_PID\" \"#{@scanner.agentPID}\")"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class Scanner
|
81
|
+
attr_reader :agentSocket, :agentPID, :found
|
82
|
+
|
83
|
+
def scan
|
84
|
+
@found = false
|
85
|
+
procs = Sys::ProcTable.ps(smaps: false, cgroup: false).select do
|
13
86
|
|p|
|
14
|
-
|
87
|
+
res = p.cmdline =~ /ssh-agent/ && p.cmdline !~ /--session=ubuntu/ && p.state != 'Z'
|
88
|
+
res
|
15
89
|
end
|
16
90
|
return if procs.empty?
|
17
|
-
|
91
|
+
|
92
|
+
p = procs.first
|
18
93
|
p.cmdline =~ /ssh-agent\s-a ([-.a-zA-Z0-9_\/]+)/
|
19
|
-
return
|
20
|
-
|
94
|
+
return unless $LAST_MATCH_INFO
|
95
|
+
|
96
|
+
@found = true
|
97
|
+
@agentSocket = $LAST_MATCH_INFO[1]
|
21
98
|
@agentPID = p.pid
|
22
99
|
end
|
23
|
-
|
24
|
-
def
|
25
|
-
|
26
|
-
print "SSH_AUTH_SOCK=#{@agentSocket}; "
|
27
|
-
puts "export SSH_AUTH_SOCK;"
|
28
|
-
print "SSH_AGENT_PID=#{@agentPID}; "
|
29
|
-
puts "export SSH_AGENT_PID;"
|
30
|
-
puts "echo Agent pid #{@agentPID};"
|
100
|
+
|
101
|
+
def found?
|
102
|
+
@found
|
31
103
|
end
|
104
|
+
|
32
105
|
end
|
106
|
+
|
33
107
|
end
|
34
108
|
end
|
35
109
|
end
|
metadata
CHANGED
@@ -1,38 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ssh-locate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.4.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Arnaud Meuret
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2022-07-15 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: sys-proctable
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: thor
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - ">="
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
34
|
type: :runtime
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
36
41
|
description: A CLI tool and its associated Ruby library that help you locate and reconnect
|
37
42
|
to a running SSH agent. Useful in automation scenarios where multiple processes
|
38
43
|
must repeatedly open SSH connections leveraging a one-time authentication pass
|
@@ -43,7 +48,9 @@ executables:
|
|
43
48
|
extensions: []
|
44
49
|
extra_rdoc_files: []
|
45
50
|
files:
|
46
|
-
- .
|
51
|
+
- ".github/workflows/ruby.yml"
|
52
|
+
- ".gitignore"
|
53
|
+
- ".travis.yml"
|
47
54
|
- Gemfile
|
48
55
|
- Guardfile
|
49
56
|
- README.md
|
@@ -58,26 +65,28 @@ files:
|
|
58
65
|
- ssh-locate.gemspec
|
59
66
|
homepage: ''
|
60
67
|
licenses: []
|
61
|
-
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
62
70
|
rdoc_options: []
|
63
71
|
require_paths:
|
64
72
|
- lib
|
65
73
|
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
74
|
requirements:
|
68
|
-
- -
|
75
|
+
- - ">="
|
69
76
|
- !ruby/object:Gem::Version
|
70
77
|
version: '0'
|
71
78
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
-
none: false
|
73
79
|
requirements:
|
74
|
-
- -
|
80
|
+
- - ">="
|
75
81
|
- !ruby/object:Gem::Version
|
76
82
|
version: '0'
|
77
83
|
requirements: []
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
specification_version: 3
|
84
|
+
rubygems_version: 3.3.7
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
82
87
|
summary: A tool (+ a Ruby lib) to locate a running SSH agent
|
83
|
-
test_files:
|
88
|
+
test_files:
|
89
|
+
- features/agent-ids.feature
|
90
|
+
- features/step_definitions/agent-ids.rb
|
91
|
+
- features/support/env.rb
|
92
|
+
- features/support/hooks.rb
|