ssh-locate 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +35 -0
- data/.travis.yml +3 -3
- data/Gemfile +1 -0
- data/README.md +42 -4
- data/features/agent-ids.feature +13 -5
- data/features/step_definitions/agent-ids.rb +5 -8
- data/lib/net/ssh/locate/version.rb +1 -1
- data/lib/net/ssh/locate.rb +68 -31
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 784e22cc6152ba4f53793125ac7c02f1ce31601aa839578fa293efdd7e7a7acc
|
4
|
+
data.tar.gz: ab574c8e2d68d9b7259ce0ec9c893cda059b8582bee7af4151210e6130482f5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
rvm:
|
2
|
-
- 2.6.
|
3
|
-
|
4
|
-
|
2
|
+
- 2.6.9
|
3
|
+
- 2.7.5
|
4
|
+
- 3.1.1
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,14 +1,24 @@
|
|
1
1
|
ssh-locate
|
2
2
|
==========
|
3
3
|
[](http://travis-ci.org/ameuret/ssh-locate)
|
4
|
+

|
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
|
4
16
|
|
5
|
-
A command line tool that helps you locate and contact a SSH agent launched in a separate session.
|
6
|
-
|
7
17
|
Features
|
8
18
|
--------
|
9
19
|
- output is fully compatible with openSSH:
|
10
20
|
|
11
|
-
```
|
21
|
+
``` bash
|
12
22
|
SSH_AUTH_SOCK=/tmp/ssh-locate-test.15970; export SSH_AUTH_SOCK;
|
13
23
|
SSH_AGENT_PID=12427; export SSH_AGENT_PID;
|
14
24
|
echo Agent pid 12427;
|
@@ -16,6 +26,20 @@ Features
|
|
16
26
|
|
17
27
|
- supports the Fish shell
|
18
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:
|
37
|
+
|
38
|
+
``` emacs-lisp
|
39
|
+
(setenv "SSH_AUTH_SOCK" "/tmp/zed")
|
40
|
+
(setenv "SSH_AGENT_PID" "3216002")
|
41
|
+
```
|
42
|
+
|
19
43
|
Installation
|
20
44
|
------------
|
21
45
|
|
@@ -30,8 +54,22 @@ Launch your SSH agent and tell it to use a specific socket file with the -a opti
|
|
30
54
|
|
31
55
|
In a later shell (or any process running for the user who owns the agent):
|
32
56
|
|
57
|
+
### Bash
|
58
|
+
|
33
59
|
$ eval `ssh-locate`
|
34
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
|
35
73
|
|
36
74
|
Fish startup
|
37
75
|
------------
|
@@ -39,7 +77,7 @@ Fish startup
|
|
39
77
|
You can launch and activate an agent at startup by adding this to your config.fish:
|
40
78
|
|
41
79
|
ssh-agent -a /tmp/arnaud
|
42
|
-
|
80
|
+
ssh-locate | source
|
43
81
|
|
44
82
|
Caveat
|
45
83
|
------
|
data/features/agent-ids.feature
CHANGED
@@ -14,12 +14,13 @@ Feature: Agent IDs
|
|
14
14
|
And the output should contain the correct agent PID
|
15
15
|
And the output should contain the correct agent socket
|
16
16
|
|
17
|
-
Scenario: No agent is running or
|
17
|
+
Scenario: No agent is running or locatable
|
18
18
|
Given no agent is running
|
19
19
|
When I run `ssh-locate`
|
20
20
|
Then the output should be empty
|
21
21
|
|
22
|
-
|
22
|
+
@focus
|
23
|
+
Scenario: Locate an agent that shows its socket in the command line
|
23
24
|
Given an ssh agent has been launched with a specific socket
|
24
25
|
Given the user's shell is Bash
|
25
26
|
When I run `ssh-locate`
|
@@ -29,7 +30,7 @@ Feature: Agent IDs
|
|
29
30
|
And the output should contain "export SSH_AGENT_PID;"
|
30
31
|
And the output should contain the correct agent PID
|
31
32
|
And the output should contain the correct agent socket
|
32
|
-
|
33
|
+
|
33
34
|
Scenario: Recognize and honor the agent managed by Ubuntu
|
34
35
|
Given an ssh agent has been launched in my Ubuntu session
|
35
36
|
When I run `ssh-locate`
|
@@ -39,7 +40,7 @@ Feature: Agent IDs
|
|
39
40
|
And the output should contain "export SSH_AGENT_PID;"
|
40
41
|
And the output should contain the correct agent PID
|
41
42
|
And the output should contain the correct agent socket
|
42
|
-
|
43
|
+
|
43
44
|
Scenario: Ignore agents run by someone else
|
44
45
|
Given an ssh agent is running for another user
|
45
46
|
And no ssh agent is running for me
|
@@ -54,4 +55,11 @@ Feature: Agent IDs
|
|
54
55
|
And the output should contain "set -x SSH_AGENT_PID"
|
55
56
|
And the output should contain the correct agent PID
|
56
57
|
And the output should contain the correct agent socket
|
57
|
-
|
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
|
@@ -33,21 +33,18 @@ Then /^the output should be empty$/ do
|
|
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
42
|
|
43
43
|
Given("the user's shell is Fish") do
|
44
|
-
|
45
|
-
# passwdEntry = `getent passwd #{ENV['USER']}`
|
46
|
-
# expect(passwdEntry).to match(/fish$/)
|
44
|
+
set_environment_variable('SHELL', 'fish')
|
47
45
|
end
|
48
46
|
|
49
47
|
Given("the user's shell is Bash") do
|
50
|
-
|
51
|
-
# passwdEntry = `getent passwd #{ENV['USER']}`
|
52
|
-
# expect(passwdEntry).to match(/fish$/)
|
48
|
+
set_environment_variable('SHELL', 'bash')
|
53
49
|
end
|
50
|
+
|
data/lib/net/ssh/locate.rb
CHANGED
@@ -1,21 +1,49 @@
|
|
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
|
13
38
|
@scanner.scan
|
14
39
|
end
|
15
|
-
|
40
|
+
|
16
41
|
def print_shell_commands
|
17
42
|
return unless @scanner.found?
|
18
|
-
|
43
|
+
|
44
|
+
if options[:emacs]
|
45
|
+
emacsOutput
|
46
|
+
elsif usingFish?
|
19
47
|
fishOutput
|
20
48
|
else
|
21
49
|
bashOutput
|
@@ -23,44 +51,53 @@ module Net
|
|
23
51
|
end
|
24
52
|
|
25
53
|
private
|
26
|
-
def usingFish?
|
27
|
-
passwdEntry = `getent passwd #{ENV['USER']}`
|
28
|
-
passwdEntry =~ /fish$/
|
29
|
-
end
|
30
54
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
43
78
|
end
|
44
|
-
|
79
|
+
|
45
80
|
class Scanner
|
46
|
-
|
47
81
|
attr_reader :agentSocket, :agentPID, :found
|
48
|
-
|
82
|
+
|
49
83
|
def scan
|
50
84
|
@found = false
|
51
|
-
procs = Sys::ProcTable.ps.select do
|
85
|
+
procs = Sys::ProcTable.ps(smaps: false, cgroup: false).select do
|
52
86
|
|p|
|
53
|
-
|
87
|
+
res = p.cmdline =~ /ssh-agent/ && p.cmdline !~ /--session=ubuntu/ && p.state != 'Z'
|
88
|
+
res
|
54
89
|
end
|
55
90
|
return if procs.empty?
|
56
|
-
|
91
|
+
|
92
|
+
p = procs.first
|
57
93
|
p.cmdline =~ /ssh-agent\s-a ([-.a-zA-Z0-9_\/]+)/
|
58
|
-
return
|
94
|
+
return unless $LAST_MATCH_INFO
|
95
|
+
|
59
96
|
@found = true
|
60
|
-
@agentSocket = $1
|
97
|
+
@agentSocket = $LAST_MATCH_INFO[1]
|
61
98
|
@agentPID = p.pid
|
62
99
|
end
|
63
|
-
|
100
|
+
|
64
101
|
def found?
|
65
102
|
@found
|
66
103
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ssh-locate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnaud Meuret
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sys-proctable
|
@@ -48,6 +48,7 @@ executables:
|
|
48
48
|
extensions: []
|
49
49
|
extra_rdoc_files: []
|
50
50
|
files:
|
51
|
+
- ".github/workflows/ruby.yml"
|
51
52
|
- ".gitignore"
|
52
53
|
- ".travis.yml"
|
53
54
|
- Gemfile
|
@@ -65,7 +66,7 @@ files:
|
|
65
66
|
homepage: ''
|
66
67
|
licenses: []
|
67
68
|
metadata: {}
|
68
|
-
post_install_message:
|
69
|
+
post_install_message:
|
69
70
|
rdoc_options: []
|
70
71
|
require_paths:
|
71
72
|
- lib
|
@@ -80,8 +81,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
81
|
- !ruby/object:Gem::Version
|
81
82
|
version: '0'
|
82
83
|
requirements: []
|
83
|
-
rubygems_version: 3.
|
84
|
-
signing_key:
|
84
|
+
rubygems_version: 3.3.7
|
85
|
+
signing_key:
|
85
86
|
specification_version: 4
|
86
87
|
summary: A tool (+ a Ruby lib) to locate a running SSH agent
|
87
88
|
test_files:
|