simple_ssh
Simple SSH
Simple SSH enables running commands against a remote host via SSH. It is not an implementation of the protocol, but relies on any existing SSH client program installed on the client machine (eg: OpenSSH).
Simple SSH is stateless, in that a connection is initiated and terminated for every request, after a response is received. Commands can be pipelined, allowing to send multiple commands in a single request.
Simple SSH assumes public key authentication, where a client's public key is expected to be listed in the server's ~/.ssh/authorized_keys
file. No other authentication methods are supported at this time.
Installation
-
Add the dependency to your
shard.yml
:dependencies: simple_ssh: github: GrottoPress/simple_ssh
-
Run
shards install
Usage
-
Run single command:
require "simple_ssh" ssh = SimpleSsh.new("root", ip: "127.0.0.1") # <= `port:` defaults to '22' ssh.run("ls /root") do |response| puts response.status.success? # <= true response.output.try do |output| ouput.each_line { |line| puts line } end response.error.try do |error| error.each_line { |line| puts line } end end
-
Run multiple (pipelined) commands:
require "simple_ssh" ssh = SimpleSsh.new("username", "my.host.name", 2222) ssh << "ls /root" ssh << "cat /non-existent" # <= Alias: `ssh.command(...)` ssh.run do |responses| puts responses.size # <= 2 # <= Responses follow the order of the commands: # <= `responses[0]` is for "ls /root" # <= `responses[1]` is for "cat /non-existent" responses.each do |response| puts response.status.exit_code response.output.try do |output| ouput.each_line { |line| puts line } end response.error.try do |error| error.each_line { |line| puts line } end end end
Development
Run tests with docker-compose run --rm spec
. If you need to update shards before that, run docker-compose run --rm shards
.
Contributing
- Fork it
- Switch to the
master
branch:git checkout master
- Create your feature branch:
git checkout -b my-new-feature
- Make your changes, updating changelog and documentation as appropriate.
- Commit your changes:
git commit
- Push to the branch:
git push origin my-new-feature
- Submit a new Pull Request against the
GrottoPress:master
branch.
simple_ssh
- 5
- 0
- 0
- 0
- 1
- 7 months ago
- May 8, 2021
MIT License
Sat, 21 Dec 2024 10:29:54 GMT