ssh4iot 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 03c1e22d177e72e2dae54a95cf8f2f819528711a9f13481f7688bec6ef0f4b89
4
+ data.tar.gz: cb6cc9ce40b995f09d846d202710b038303d66c3aa45ce9afaa9561c15fda4c3
5
+ SHA512:
6
+ metadata.gz: 738a7f3382b3e0e5089729eede2d51276f4ebd9fab5abb7064f5135fc98ee257ccc845a56dca63758154aec12af5354fe11771e691e0eae424e9590f5b7f0425
7
+ data.tar.gz: df5971149412ebf06550b421b6616f6dc563e0600b7d0678333d39ffb3950f26f137a694dcbbd9a02c91616832c1bccfdf8c124618efd347424566ebff806360
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .idea
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at mpantel@aegean.gr. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
@@ -0,0 +1,43 @@
1
+ FROM ruby:2.7.2
2
+
3
+ # throw errors if Gemfile has been modified since Gemfile.lock
4
+ RUN bundle config --global frozen 1 \
5
+ && apt-get update && apt-get install -y openssh-server \
6
+ && apt-get autoremove && apt-get clean && apt-get autoclean && rm -rf /var/lib/apt/lists/* \
7
+ && service ssh start #\
8
+ #&& gem install ssh4iot
9
+
10
+
11
+ CMD ["ruby ssh4iot/exe/ssh4iot-server -p 80 -e production"]
12
+
13
+ #You can then build and run the Ruby image:
14
+ #
15
+ #$ docker build -t my-ruby-app .
16
+ #$ docker run -it --name my-running-script my-ruby-app
17
+ #
18
+ #Generate a Gemfile.lock
19
+ #
20
+ #The above example Dockerfile expects a Gemfile.lock in your app directory. This docker run will help you generate one. Run it in the root of your app, next to the Gemfile:
21
+ #
22
+ #$ docker run --rm -v "$PWD":/usr/src/app -w /usr/src/app ruby:2.7.2 bundle install
23
+ #
24
+ #Run a single Ruby script
25
+ #
26
+ #For many simple, single file projects, you may find it inconvenient to write a complete Dockerfile. In such cases, you can run a Ruby script by using the Ruby Docker image directly:
27
+ #
28
+ #$ docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp ruby:2.5 ruby your-daemon-or-script.rb
29
+ #
30
+ #Encoding
31
+ #
32
+ #By default, Ruby inherits the locale of the environment in which it is run. For most users running Ruby on their desktop systems, that means it's likely using some variation of *.UTF-8 (en_US.UTF-8, etc). In Docker however, the default locale is C, which can have unexpected results. If your application needs to interact with UTF-8, it is recommended that you explicitly adjust the locale of your image/container via -e LANG=C.UTF-8 or ENV LANG C.UTF-8.
33
+
34
+ #The following example starts a Redis container and configures it to always restart unless it is explicitly stopped or Docker is restarted.
35
+ #
36
+ #$ docker run -d --restart unless-stopped redis
37
+ #
38
+ #This command changes the restart policy for an already running container named redis.
39
+ #
40
+ #$ docker update --restart unless-stopped redis
41
+ #docker run -p 2020:80 -it --name ssh4iot --label traefik.backend=ssh4iot ssh4iot sh
42
+ ##docker run -v ssh4iot:/home --expose 80 -p 2020:22 -it --name ssh4iot --label traefik.backend=ssh4iot --label traefik.frontend.rule="Host:myhost.example.com;PathPrefixStrip:/ssh4iot" --label traefik.frontend.entryPoints=http,https ssh4iot sh
43
+
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ssh4iot.gemspec
4
+ gemspec
5
+
@@ -0,0 +1,82 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ssh4iot (0.0.1)
5
+ jwt
6
+ mongoid (~> 7.0)
7
+ net-ssh
8
+ openssl
9
+ rake (~> 12.0)
10
+ sinatra (~> 2.0)
11
+ whenever
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ activemodel (6.0.3.4)
17
+ activesupport (= 6.0.3.4)
18
+ activesupport (6.0.3.4)
19
+ concurrent-ruby (~> 1.0, >= 1.0.2)
20
+ i18n (>= 0.7, < 2)
21
+ minitest (~> 5.1)
22
+ tzinfo (~> 1.1)
23
+ zeitwerk (~> 2.2, >= 2.2.2)
24
+ bson (4.10.0)
25
+ byebug (11.1.3)
26
+ chronic (0.10.2)
27
+ concurrent-ruby (1.1.7)
28
+ diff-lcs (1.4.4)
29
+ i18n (1.8.5)
30
+ concurrent-ruby (~> 1.0)
31
+ jwt (2.2.2)
32
+ minitest (5.14.2)
33
+ mongo (2.13.0)
34
+ bson (>= 4.8.2, < 5.0.0)
35
+ mongoid (7.1.2)
36
+ activemodel (>= 5.1, < 6.1)
37
+ mongo (>= 2.7.0, < 3.0.0)
38
+ mustermann (1.1.1)
39
+ ruby2_keywords (~> 0.0.1)
40
+ net-ssh (6.1.0)
41
+ openssl (2.2.0)
42
+ rack (2.2.3)
43
+ rack-protection (2.1.0)
44
+ rack
45
+ rake (12.3.3)
46
+ rspec (3.9.0)
47
+ rspec-core (~> 3.9.0)
48
+ rspec-expectations (~> 3.9.0)
49
+ rspec-mocks (~> 3.9.0)
50
+ rspec-core (3.9.3)
51
+ rspec-support (~> 3.9.3)
52
+ rspec-expectations (3.9.2)
53
+ diff-lcs (>= 1.2.0, < 2.0)
54
+ rspec-support (~> 3.9.0)
55
+ rspec-mocks (3.9.1)
56
+ diff-lcs (>= 1.2.0, < 2.0)
57
+ rspec-support (~> 3.9.0)
58
+ rspec-support (3.9.3)
59
+ ruby2_keywords (0.0.2)
60
+ sinatra (2.1.0)
61
+ mustermann (~> 1.0)
62
+ rack (~> 2.2)
63
+ rack-protection (= 2.1.0)
64
+ tilt (~> 2.0)
65
+ thread_safe (0.3.6)
66
+ tilt (2.0.10)
67
+ tzinfo (1.2.7)
68
+ thread_safe (~> 0.1)
69
+ whenever (1.0.0)
70
+ chronic (>= 0.6.3)
71
+ zeitwerk (2.4.0)
72
+
73
+ PLATFORMS
74
+ ruby
75
+
76
+ DEPENDENCIES
77
+ byebug
78
+ rspec (~> 3.0)
79
+ ssh4iot!
80
+
81
+ BUNDLED WITH
82
+ 2.1.4
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Michail!
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 michail
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,85 @@
1
+ # ssh4iot
2
+ Easy way to configure and register reverse ssh tunnels for iot devices by key sharing over https to manage and enjoy
3
+
4
+ **PRERELEASE**
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'ssh4iot'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle install
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install ssh4iot
21
+
22
+ ## Usage
23
+
24
+ TODO: Write usage instructions here
25
+
26
+ ## Development
27
+
28
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
29
+
30
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
31
+
32
+ ## Contributing
33
+
34
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ssh4iot. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/ssh4iot/blob/master/CODE_OF_CONDUCT.md).
35
+
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Ssh4iot project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/ssh4iot/blob/master/CODE_OF_CONDUCT.md).
44
+
45
+
46
+ # Intoduction
47
+
48
+ When deploying several iot devices on a private network and there is a need to manage them centrally for updates and administration. While the most appropriate way of interacting with these devices is through ssh connections there are many conciderations when the number of appliances grows beyond a couple of devices. More over we need to group these appliances into groups based on some organizational criteria namelly to split up administration. We aim at minimizing the setup needs for the appliances to:
49
+
50
+ 1. the server address
51
+ 2. one shared api token per deployment group for the initial setup
52
+ 3. one identifier per device
53
+
54
+ # Architecture
55
+
56
+ - Server:
57
+ 1. Web application/administration
58
+ 2. Repository
59
+ 3. one user per deployment group
60
+ 4. ssh server
61
+
62
+ - Client:
63
+ 1. Client application
64
+ 2. one user per client device
65
+ 3. autossh
66
+
67
+ # Considerations
68
+
69
+ 1. initial setup
70
+ 2. networking and wifi registration
71
+ 3. security
72
+
73
+ # Implementation
74
+
75
+ # Case Study
76
+
77
+ Given a deployment which uses many Raspberry Pi's with SenseHat to collect environmental measuremements from an number of buildings, storing them in a central data base, we need an easy way to register and manage devices
78
+
79
+ # References
80
+ https://xtermjs.org/
81
+ https://github.com/huashengdun/webssh
82
+ https://github.com/stuicey/SSHy
83
+
84
+ https://www.rubydoc.info/github/net-ssh/net-ssh/Net/SSH
85
+ https://net-ssh.github.io/net-ssh/
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ssh4iot"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "ssh4iot"
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "server"
File without changes
@@ -0,0 +1,92 @@
1
+ require 'optparse'
2
+
3
+ class Parameter
4
+ def self.parse(options)
5
+ args = {}
6
+
7
+ opt_parser = OptionParser.new do |opts|
8
+
9
+ opts.banner = <<BANNER
10
+
11
+ Usage: #{File.basename($0)} [options]
12
+
13
+ Server:
14
+
15
+ starts docker ssh server and awaits connections
16
+
17
+ Client:
18
+
19
+ generate reverse proxy
20
+
21
+ BANNER
22
+
23
+ opts.on("-s", "--server", "Server Operation") do |n|
24
+ args[:server] = n
25
+ end
26
+ opts.on("-c", "--client", "Client Operation") do |n|
27
+ args[:client] = n
28
+ end
29
+ opts.on("--cron-setup", "Register as cron job") do |n|
30
+ args[:cron_setup] = n
31
+ end
32
+ opts.on("--cron-cleanup", "Unregister as cron job") do |n|
33
+ args[:cron_cleanup] = n
34
+ end
35
+
36
+ args[:host] = 'localhost'
37
+ opts.on("--host=HOSTNAME", "Server hostname accessed as https://HOSTNAME") do |n|
38
+ args[:host] = n
39
+ end
40
+ opts.on("--user=USER", "Connect to Server as USER") do |n|
41
+ args[:host] = n
42
+ end
43
+ args[:port] = '2020'
44
+ opts.on("-p", "--port=PORT", "Server port for ssh") do |n|
45
+ args[:port] = n
46
+ end
47
+
48
+ args[:container] = 'ssh4iot'
49
+ opts.on("--container=CONTAINER", "Docker container") do |n|
50
+ args[:container] = n
51
+ end
52
+ opts.on("--list", "list registered") do |n|
53
+ args[:list] = n
54
+ end
55
+ opts.on("--authorize", "Authorize request") do |n|
56
+ args[:authorize] = n
57
+ end
58
+
59
+ opts.on("--register", "Request autorization") do |n|
60
+ args[:register] = n
61
+ end
62
+ opts.on("--unregister", "Request autorization") do |n|
63
+ args[:unregister] = n
64
+ end
65
+
66
+ opts.on("--connect", "initiate remote proxy") do |n|
67
+ args[:connect] = n
68
+ end
69
+ opts.on("--ping", "initiate remote proxy") do |n|
70
+ args[:ping] = n
71
+ end
72
+ args[:range] = "10000:11000"
73
+ opts.on("--range=RANGE", "initiate remote proxy") do |n|
74
+ args[:range] = n
75
+ end
76
+
77
+ opts.on("-h", "--help", "Prints this help") do
78
+ puts opts
79
+ exit
80
+ end
81
+ end
82
+
83
+ opt_parser.parse!(options)
84
+ lower,upper = args[:range].split(":")
85
+ return args.merge(Hash[["lower","upper"].zip( args[:range].split(":").sort)]).merge({subject: ARGV}) # ssh users
86
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
87
+
88
+ puts ["\nError:\n------\n", e.message, "\n------\n"]
89
+ opt_parser.parse!(['-h'])
90
+
91
+ end
92
+ end
@@ -0,0 +1,13 @@
1
+ require 'sinatra'
2
+
3
+ get '/:identifier' do
4
+ "Get #{params[:identifier]}"
5
+ end
6
+
7
+ post '/:identifier/:public_key' do
8
+ "Post id: #{params[:identifier]} key: #{params[:public_key]}"
9
+ end
10
+
11
+ delete '/:identifier' do
12
+ "Delete #{params[:identifier]}"
13
+ end
@@ -0,0 +1,76 @@
1
+ require "ssh4iot/version"
2
+ require "parameter"
3
+
4
+ require 'rake'
5
+ require 'rake/file_utils_ext'
6
+
7
+ require 'net/ssh'
8
+ require 'logger'
9
+
10
+ module Ssh4iot
11
+ class Error < StandardError; end
12
+
13
+ parameters = Parameter.parse(ARGV)
14
+ pp parameters if parameters[:review]
15
+
16
+ def clear_docker
17
+ sh "docker rm -f #{params['container']}"
18
+ end
19
+ def start_server
20
+ sh "docker build -t #{params['container']} . && docker run -d --restart unless-stopped -v ~/ssh4iot:/home --expose 80 -p #{parameters['port']}:22 -it --name #{params['container']} --label traefik.backend=ssh4iot --label traefik.frontend.rule=\"Host:#{parameters['host']};PathPrefixStrip:/ssh4iot\" --label traefik.frontend.entryPoints=http,https #{params['container']} sh"
21
+ end
22
+
23
+ def remove_user(user)
24
+ sh "deluser --remove-home #{user}"
25
+ end
26
+ def add_user(user)
27
+ sh "useradd #{user} && mkdir /home/#{user} && chown -R #{user}#{user} /home/#{user}"
28
+ end
29
+
30
+ def keygen
31
+ sh "ssh-keygen -q -t rsa -f ~/.ssh/id_rsa -N ''"
32
+ end
33
+ def register_key
34
+ sh "cat ~/.ssh/id_rsa.pub | ssh demo@198.51.100.0 \"mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys\""
35
+ end
36
+
37
+ def reverse_proxy(port,key_path)
38
+ # https://www.rubydoc.info/github/net-ssh/net-ssh/Net/SSH
39
+ # https://net-ssh.github.io/ssh/v1/chapter-3.html#s2
40
+
41
+ Net::SSH.start(
42
+ parameters['host'], parameters['user'],
43
+ :keys => [ key_path ],
44
+ #:compression => "zlib"
45
+ ) do |session|
46
+ session.forward.remote(params["port"], parameters['host'], port)
47
+ session.loop { true }
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+
54
+
55
+
56
+ __END__
57
+ X == “execute a command and capture the output”
58
+
59
+ Net::SSH.start("host", "user", password: "password") do |ssh|
60
+ result = ssh.exec!("ls -l")
61
+ puts result
62
+ end
63
+
64
+ X == “forward connections on a local port to a remote host”
65
+
66
+ Net::SSH.start("host", "user", password: "password") do |ssh|
67
+ ssh.forward.local(1234, "www.google.com", 80)
68
+ ssh.loop { true }
69
+ end
70
+
71
+ X == “forward connections on a remote port to the local host”
72
+
73
+ Net::SSH.start("host", "user", password: "password") do |ssh|
74
+ ssh.forward.remote(80, "www.google.com", 1234)
75
+ ssh.loop { true }
76
+ end
@@ -0,0 +1,3 @@
1
+ module Ssh4iot
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,47 @@
1
+ 1 login to server
2
+ 2 add team user (no password)
3
+ adduser team_username
4
+ 3 create key pair
5
+ https://www.linuxbabe.com/linux-server/setup-passwordless-ssh-login
6
+ a. create
7
+ ssh-keygen -t rsa -b 4096
8
+ b. copy id to each team member as team member username (pi)
9
+ ssh-copy-id pi@team.member
10
+
11
+ 4 for each team member
12
+ 1 install autoshh (https://www.everythingcli.org/ssh-tunnelling-for-fun-and-profit-autossh/)
13
+ sudo apt-get install autossh
14
+ 2 create key pair
15
+ a. ssh-keygen -t rsa -b 4096
16
+
17
+ b. copy id to server as team_username
18
+ ssh-copy-id team_user@server
19
+ 3 setup reverse tunel (https://handyman.dulare.com/ssh-tunneling-with-autossh/)
20
+
21
+ create file
22
+ mkdir -p ~/.local/share/systemd/user
23
+ vi ~/.local/share/systemd/user/reverse_ssh.service
24
+ # set a uniq port for each other like 2222
25
+ [Unit]
26
+ Description=AutoSSH tunnel service for remote port 10003 to local 22
27
+ After=network.target
28
+ [Service]
29
+ Environment="AUTOSSH_GATETIME=0"
30
+ ExecStart=/usr/bin/autossh -o "ServerAliveInterval 10" -o "ServerAliveCountMax 3" -N -R 10003:localhost:22 terriade@psmart.aegean.gr
31
+ [Install]
32
+ WantedBy=multi-user.target
33
+
34
+ start service as pi user
35
+ https://superuser.com/questions/1215631/how-to-run-systemctl-service-as-user
36
+
37
+ systemctl --user daemon-reload
38
+ systemctl --user start reverse_ssh.service
39
+ systemctl --user enable reverse_ssh.service
40
+ systemctl --user status reverse_ssh.service
41
+ sudo netstat -ntlp | grep LISTEN
42
+
43
+ then:
44
+
45
+ ssh pi@127.0.0.1 -p 2222
46
+
47
+
@@ -0,0 +1,42 @@
1
+ require_relative 'lib/ssh4iot/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "ssh4iot"
5
+ spec.version = Ssh4iot::VERSION
6
+ spec.authors = ["Michail Pantelelis"]
7
+ spec.email = ["mpantel@aegean.gr"]
8
+
9
+ spec.summary = %q{Easy way to configure and register reverse ssh tunnels for iot devices by keysharing over https to manage and enjoy}
10
+ spec.description = %q{Easy way to configure and register reverse ssh tunnels for iot devices by keysharing over https to manage and enjoy}
11
+ spec.homepage = "https://github.com/mpantel/ssh4iot"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ #spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/mpantel/ssh4iot"
19
+ spec.metadata["changelog_uri"] = "https://github.com/mpantel/ssh4iot"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_runtime_dependency 'rake', '~> 12.0'
31
+ spec.add_runtime_dependency 'openssl'
32
+ spec.add_runtime_dependency 'net-ssh'
33
+ spec.add_runtime_dependency 'whenever'
34
+ #spec.add_runtime_dependency 'thin'
35
+ spec.add_runtime_dependency 'sinatra','~> 2.0'
36
+ spec.add_runtime_dependency 'jwt'
37
+ spec.add_runtime_dependency 'mongoid','~> 7.0'
38
+
39
+ spec.add_development_dependency 'rspec', '~> 3.0'
40
+ spec.add_development_dependency 'byebug'
41
+
42
+ end
metadata ADDED
@@ -0,0 +1,198 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ssh4iot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michail Pantelelis
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-10-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '12.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '12.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: openssl
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: net-ssh
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: whenever
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sinatra
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: jwt
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: mongoid
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '7.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '7.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: byebug
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Easy way to configure and register reverse ssh tunnels for iot devices
140
+ by keysharing over https to manage and enjoy
141
+ email:
142
+ - mpantel@aegean.gr
143
+ executables:
144
+ - ssh4iot
145
+ - ssh4iot-server
146
+ extensions: []
147
+ extra_rdoc_files: []
148
+ files:
149
+ - ".gitignore"
150
+ - ".rspec"
151
+ - ".travis.yml"
152
+ - CODE_OF_CONDUCT.md
153
+ - Dockerfile
154
+ - Gemfile
155
+ - Gemfile.lock
156
+ - LICENSE
157
+ - LICENSE.txt
158
+ - README.md
159
+ - Rakefile
160
+ - bin/console
161
+ - bin/setup
162
+ - exe/ssh4iot
163
+ - exe/ssh4iot-server
164
+ - lib/client.rb
165
+ - lib/parameter.rb
166
+ - lib/server.rb
167
+ - lib/ssh4iot.rb
168
+ - lib/ssh4iot/version.rb
169
+ - notes.md
170
+ - ssh4iot.gemspec
171
+ homepage: https://github.com/mpantel/ssh4iot
172
+ licenses:
173
+ - MIT
174
+ metadata:
175
+ homepage_uri: https://github.com/mpantel/ssh4iot
176
+ source_code_uri: https://github.com/mpantel/ssh4iot
177
+ changelog_uri: https://github.com/mpantel/ssh4iot
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: 2.3.0
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ requirements: []
193
+ rubygems_version: 3.1.4
194
+ signing_key:
195
+ specification_version: 4
196
+ summary: Easy way to configure and register reverse ssh tunnels for iot devices by
197
+ keysharing over https to manage and enjoy
198
+ test_files: []