Coder Social home page Coder Social logo

ssh_server_manager's Introduction

SSHServerManager

Just a simple utility to help you setup SSH for your application.

I wrote this because docker terminal pipes are terrible and crash all the time for me, and doing a docker terminal to iex -S mix phoenix.server or similar to connect into an IEx on the active app is a pain. Now I just point ssh at it, and everything is awesome.

Check out http://erlang.org/doc/man/ssh.html

Required Stuff

  • :ssh app is started (should come with your erlang)
  • Have a RSA and/or DSA private key (and maybe others)
  • Provide public keys for authentication via the SSHServerManager.KeyAuthenticator behavior
    • KeyAuthenticator.Explicit lets you pass in an array of public keys
    • KeyAuthenticator.File lets you pass in a path to an authroized_keys file
    • Implement your own

Configure

Be sure you add :ssh to your applications.

Add a worker to your supervision tree like

[
  worker(SSHServerManager, [[
    keys: [File.read!("private.rsa"), File.read!("private.dsa")], # Any private key format should work
    key_authenticator: [
      module: SSHServerManager.KeyAuthenticator.Explicit, # Also, .File or your own
      config: [
        "ssh-rsa xxxxxxxxxxx",
        "ssh-dss xxxxxxxxxx"
      ]
    ],
    port: 10022, # default 22, which is only really good for docker
    id_string: "My Awesome Server!", # SSH ID string to client, default to node name
    # shell: :iex, # default
    # shell: :erl,
    # shell: {module, method, args},
    # single_user: false # set to true to only allow one active user
  ]])
]

Or manually start it with SSHServerMangaer.start(keys: ....)

Implement your own authenticator

defmodule MyAuth do
  @behaviour SSHServerManager.KeyAuthenticator

  # config from key_authenticator hash goes in
  def init(_config), do: {:ok, nil}

  # result, other than the :ok, goes into the config here
  def is_auth_key(key, _user, _config) do
    user = Accounts.get_ssh_user(key) # or by user name passed in
    if user.has_shell_access do
      Logger.info("#{user.name} logged in via ssh.")
      true
    else
      Logger.warn("#{user.name} tried to login via ssh!")
      false
    end
  end
end

Installation

If available in Hex, the package can be installed as:

  1. Add ssh_server_manager to your list of dependencies in mix.exs:
```elixir
def deps do
  [{:ssh_server_manager, "~> 0.1.0", github: "samterrell/ssh_server_manager"}]
end
```
  1. Ensure ssh_server_manager is started before your application:
```elixir
def application do
  [applications: [:ssh, :ssh_server_manager]]
end
```

ssh_server_manager's People

Stargazers

Michael Wood avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.