{"id":24755259,"url":"https://github.com/katzer/mruby-ssh","last_synced_at":"2025-10-11T01:31:36.359Z","repository":{"id":138109030,"uuid":"115261449","full_name":"katzer/mruby-ssh","owner":"katzer","description":"SSH client for mruby","archived":false,"fork":false,"pushed_at":"2024-08-24T16:30:59.000Z","size":3607,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-08-24T18:02:53.508Z","etag":null,"topics":["libssh2","mruby-gem","ssh","ssh-client"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/katzer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-24T12:28:06.000Z","updated_at":"2024-08-24T16:31:03.000Z","dependencies_parsed_at":"2023-11-10T13:27:47.949Z","dependency_job_id":"c0a65cf1-85f6-4900-a7d9-8a6c13deddff","html_url":"https://github.com/katzer/mruby-ssh","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katzer%2Fmruby-ssh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katzer%2Fmruby-ssh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katzer%2Fmruby-ssh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/katzer%2Fmruby-ssh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/katzer","download_url":"https://codeload.github.com/katzer/mruby-ssh/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236018669,"owners_count":19082129,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["libssh2","mruby-gem","ssh","ssh-client"],"created_at":"2025-01-28T12:37:58.963Z","updated_at":"2025-10-11T01:31:31.061Z","avatar_url":"https://github.com/katzer.png","language":"Ruby","readme":"# SSH client for mruby \u003cbr\u003e [![Build Status](https://travis-ci.com/katzer/mruby-ssh.svg?branch=master)](https://travis-ci.com/katzer/mruby-ssh) [![Build status](https://ci.appveyor.com/api/projects/status/bkd5aem5ap1n22cs/branch/master?svg=true)](https://ci.appveyor.com/project/katzer/mruby-ssh/branch/master) [![codebeat badge](https://codebeat.co/badges/b7257079-893a-480e-b658-80d79419d429)](https://codebeat.co/projects/github-com-katzer-mruby-ssh-master)\n\nInspired by [Net::SSH][net_ssh], empowers [mruby][mruby].\n\nThe snippet demontrates how to execute a command on the remote host:\n\n```ruby\nSSH.start('test.rebex.net', 'demo', password: 'password') do |ssh|\n  hostname = ssh.exec('hostname')\nend\n```\n\n## Installation\n\nAdd the line below to your `build_config.rb`:\n\n```ruby\nMRuby::Build.new do |conf|\n  # ... (snip) ...\n  conf.gem 'mruby-ssh'\nend\n```\n\nOr add this line to your aplication's `mrbgem.rake`:\n\n```ruby\nMRuby::Gem::Specification.new('your-mrbgem') do |spec|\n  # ... (snip) ...\n  spec.add_dependency 'mruby-ssh'\nend\n```\n\nThe resulting binary will be statically linked agains _libssh2_ and _mbedtls_. There are no external runtime dependencies and the code should run fine for Linux, Unix and Windows platform.\n\n## Usage\n\nTo initiate a SSH session it is recommended to use `SSH.start`. Next to the optional host and user, the following keys are supported: `user`, `password`, `key`, `passphrase`, `properties`, `non_interactive`, `timeout`, `compress` and `sigpipe`.\n\nPassword:\n\n```ruby\nSSH.start('test.rebex.net', 'demo', password: 'password') do |ssh|\n  ssh # =\u003e SSH::Session\nend\n```\n\nKeyboard-Interactive:\n\n```ruby\nSSH.start('test.rebex.net', 'demo') do |ssh|\n  ssh # =\u003e SSH::Session\nend\n```\n\nPublickey:\n\n```ruby\nSSH.start('test.rebex.net', 'demo', key: '~/.ssh/id_rsa', passphrase: 'optional') do |ssh|\n  ssh # =\u003e SSH::Session\nend\n```\n\nAgent:\n\n```ruby\nSSH.start('test.rebex.net', 'demo', use_agent: true) do |ssh|\n  ssh # =\u003e SSH::Session\nend\n```\n\n### SSH::Session\n\nA session class representing the connection service running on top of the SSH transport layer. It provides both low-level (connect, login, close, etc.) and high-level (open_channel, exec) SSH operations.\n\n```ruby\nSSH.start('test.rebex.net', 'demo', password: 'password') do |ssh|\n  ssh.fingerprint # =\u003e '60 C6 65 66 13 89 7B 5A 86 C5 2F 8F 7E CC 92 36 10 3B 3E 42'\nend\n```\n\nSee [session.rb](mrblib/session.rb) and [session.c](src/session.c) for a complete list of available methods.\n\n### SSH::Channel\n\nMultiple \"channels\" can be multiplexed onto a single SSH channel, each operating independently and seemingly in parallel. This class represents a single such channel. Most operations performed with the mruby-ssh library will involve using one or more channels.\n\n```ruby\nSSH.start('test.rebex.net', 'demo', password: 'password') do |ssh|\n  ssh.open_channel do |channel|\n    channel.env('MRB_VERSION', '1.4.1')\n    channel.exec('printf $MRB_VERSION') # =\u003e '1.4.1'\n  end\nend\n```\n\nTo capture both stdout and stderr streams:\n\n```ruby\nSSH.start('test.rebex.net', 'demo', password: 'password') do |ssh|\n  ssh.open_channel do |channel|\n    out, err, suc = channel.capture3(\"ruby -e '$stdout.print(1);$stderr.print(2)'\")\n  end\nend\n```\n\nTo interact with the remote process:\n\n```ruby\nSSH.start('test.rebex.net', 'demo', password: 'password') do |ssh|\n  ssh.open_channel do |channel|\n    io, suc = channel.popen2e('irb')\n\n    io.puts('1+1')\n    io.gets(chomp: true) # =\u003e '2'\n  end\nend\n```\n\nTo interact with a screen based process (like vim or emacs):\n\n```ruby\nSSH.start('test.rebex.net', 'demo', password: 'password') do |ssh|\n  ssh.open_channel do |channel|\n    channel.request_pty term: 'xterm', chars_wide: 120\n  end\nend\n```\n\nSee [channel.rb](mrblib/channel.rb) and [channel.c](src/channel.c) for a complete list of available methods.\n\n### Compression\n\nAdd the line below to your `build_config.rb`:\n\n```ruby\nMRuby::Build.new do |build|\n  # ... (snip) ...\n  build.cc.defines += %w[LIBSSH2_HAVE_ZLIB HAVE_UNISTD_H]\nend\n```\n\nNow initiate a new SSH session with `compress:true`:\n\n```ruby\nSSH.start('test.rebex.net', 'demo', password: 'password', compress: true)\n```\n\n### Threading\n\nTo initiate SSH sessions within threads add the line below to your `build_config.rb`:\n\n```ruby\nMRuby::Build.new do |build|\n  # ... (snip) ...\n  build.cc.defines += %w[MBEDTLS_THREADING_PTHREAD MBEDTLS_THREADING_C]\nend\n```\n\n### Debugging\n\nTo trace additional debug informations at runtime add the line below to your `build_config.rb`:\n\n```ruby\nMRuby::Build.new do |build|\n  # ... (snip) ...\n  build.cc.defines \u003c\u003c 'MRB_SSH_DEBUG'\nend\n```\n\n### Dynamic linking\n\nFor dynamic linking with _libssh2.so_ add the line below to your `build_config.rb`:\n\n```ruby\nMRuby::Build.new do |build|\n  # ... (snip) ...\n  build.cc.defines \u003c\u003c 'MRB_SSH_LINK_LIB'\nend\n```\n\nTo only link the crypto backend at runtime (e.g. OpenSSL) add the line below to your `build_config.rb`:\n\n```ruby\nMRuby::Build.new do |build|\n  # ... (snip) ...\n  build.cc.defines += %w[MRB_SSH_LINK_CRYPTO LIBSSH2_OPENSSL]\n  build.linker.libraries += %w[ssl crypto]\nend\n```\n\n## Development\n\nClone the repo:\n    \n    $ git clone https://github.com/katzer/mruby-ssh.git \u0026\u0026 cd mruby-ssh/\n\nCompile the source:\n\n    $ rake compile\n\nRun the tests:\n\n    $ rake test\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/katzer/mruby-ssh.\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n\n## Authors\n\n- Sebastián Katzer, Fa. appPlant GmbH\n\n## License\n\nThe mgem is available as open source under the terms of the [MIT License][license].\n\nMade with :yum: in Leipzig\n\n© 2017 [appPlant GmbH][appplant]\n\n[mruby]: https://github.com/mruby/mruby\n[net_ssh]: https://github.com/net-ssh/net-ssh\n[license]: http://opensource.org/licenses/MIT\n[appplant]: www.appplant.de","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkatzer%2Fmruby-ssh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkatzer%2Fmruby-ssh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkatzer%2Fmruby-ssh/lists"}