0.4.2 • Published 3 years ago

simple-ssh-commands v0.4.2

Weekly downloads
5
License
ISC
Repository
github
Last release
3 years ago

Simple SSH Commands

Build Status

This package aims to make executing simple SSH Commands like a git pull on your server as easy as possible. It also has a better approach to handle passwords than other packages.

All you will need is a config file with credentials (username and host) and your commands.

How to install and prepare

npm install simple-ssh-commands --save-dev

Then create a .simple-ssh-commands file in the same folder as your package.json. The content of the file should be valid JSON. Here is an example:

// .simple-ssh-commands file
{
    "username": "Test",
    "host": "example.com",
    "commands": ["cd /var/www/website", "ls -la"]
}

And that's basically it. You can run the commands by calling the binary directly:

node_modules/.bin/simple-ssh-commands

or add a script to your package.json like so:

// package.json
{
    ...
    "scripts": [
        ...
        "execute-ls-on-server": "simple-ssh-commands",
        ...
    ]
    ...
}

and then run npm run execute-ls-on-server or whatever you named you script.

Password handling

Passwords can be added to your .simple-ssh-commands file. This is only a good idea if you do not commit this file though.

This Package supports two other ways to handle your passwords:

  1. If you don't add it to your .simple-ssh-commands file you will be prompted every time to enter it when you want to run the commands. Just enter password and the commands will be run.

  2. If this process is to cumbersome for you, there is the possibility to create a .env file (if you don't already have one) in your projects root. You can add the key value pair SSC_PASSWORD=12345 (with your password) to it. The password will be taken from there if the key is found.

Multiple connections and commands

This package supports multiple connections or different commands for the same connection that can be placed in an Array in the .simple-ssh-commands file.

// .simple-ssh-commands file
[
    {
        "key": "show-content",
        "username": "name",
        "host": "example.com",
        "commands": ["cd /var/www/website", "ls -la"]
    },
    {
        "key": "git-pull",
        "username": "name",
        "host": "example.com",
        "commands": ["cd /var/www/website", "git pull"]
    }
]

If you still call the simple-ssh-commands command without an argument the first key of the array will be used. But you are now able to pass the name of the key that should be run. Here is an example of a package.json file using the feature.

// package.json
{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "show-content": "simple-ssh-commands show-content",
    "git-pull": "simple-ssh-commands git-pull"
  },
  "author": "Simon vom Eyser",
  "license": "ISC"
}

Passwords in your .env file will need the commands name as a postfix (uppercase with underscores for dashes) though.

SSC_PASSWORD_SHOW_CONTENT=12345
SSC_PASSWORD_GIT_PULL=12345

Roadmap

If somebody is interested in this let me know, there is a lot that could be optimized about this package!

  • Make it possible to provide host and username in an .env file so these things don't end up in version control
  • Add the possibility to pass a SSH-Key and use that
  • Improve server output display since it is still quite confusing.
0.4.2

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.2.4

3 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago