├── demo
└── demo.gif
├── constants.js
├── package.json
├── utils.js
├── app.js
├── LICENSE
├── .gitignore
├── README.md
├── helpers.js
└── CONTRIBUTING.MD
/demo/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Gururaj26/ssh-generator/HEAD/demo/demo.gif
--------------------------------------------------------------------------------
/constants.js:
--------------------------------------------------------------------------------
1 | const seperator = '\n' + '---------------------------------------------------' + '\n'
2 | const urlRegex = /[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi;
3 | const thanksDecorator = '///////////////// Thanks for using ssh-generator ! /////////////////';
4 |
5 | module.exports = {
6 | seperator: seperator,
7 | urlRegex: urlRegex,
8 | thanksDecorator: thanksDecorator
9 | }
10 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ssh-generator",
3 | "version": "1.1.1",
4 | "description": "Simple tool to generate ssh keys with ease of CLI.",
5 | "main": "app.js",
6 | "repository": "https://github.com/Gururaj26/ssh-generator",
7 | "author": "Gururaj Dharani",
8 | "keywords": [
9 | "ssh-generator",
10 | "ssh",
11 | "generator",
12 | "create ssh"
13 | ],
14 | "license": "MIT",
15 | "private": false,
16 | "dependencies": {
17 | "chalk-pipe": "^2.0.0",
18 | "inquirer": "^6.2.1",
19 | "joi": "^14.3.1",
20 | "rxjs": "^6.3.3",
21 | "lodash": "^4.17.19"
22 | },
23 | "publishConfig": {
24 | "registry": "https://npm.pkg.github.com/@gururaj26"
25 | },
26 | "scripts": {
27 | "patch-release": "npm version patch && npm publish"
28 | },
29 | "bin": {
30 | "ssh-generator": "app.js"
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/utils.js:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env node
2 | const inquirer = require('inquirer')
3 | const helpers = require('./helpers')
4 |
5 | var questions = [{
6 | type: 'list',
7 | name: 'domain',
8 | message: "select the domain for which you want to create ssh-key",
9 | choices: [{
10 | name: 'Github',
11 | value: 'github.com'
12 | },
13 | {
14 | name: 'Gitlab',
15 | value: 'gitlab.com'
16 | },
17 | {
18 | name: 'Bitbucket',
19 | value: 'bitbucket.org'
20 | },
21 | new inquirer.Separator(),
22 | {
23 | name: 'Custom Domain',
24 | value: 'custom_domain'
25 | }
26 | ]
27 | }, {
28 | type: 'input',
29 | name: 'username',
30 | message: 'Your username :',
31 | validate: helpers.validateName
32 | }, {
33 | type: 'confirm',
34 | name: 'isConfirm',
35 | message: 'Do you want to create your ssh key ?',
36 | }];
37 |
38 | module.exports = {
39 | 'questions': questions
40 | }
41 |
--------------------------------------------------------------------------------
/app.js:
--------------------------------------------------------------------------------
1 | #! /usr/bin/env node
2 | const inquirer = require('inquirer')
3 | // Helpers
4 | const utils = require('./utils.js')
5 | const helpers = require('./helpers.js')
6 | // helper pointers
7 | const questions = utils.questions
8 |
9 | inquirer.prompt(questions).then(answers => {
10 | let username = answers.username;
11 | let domain = answers.domain;
12 | if (answers.domain == 'custom_domain') {
13 | inquirer.prompt({
14 | type: 'input',
15 | name: 'domain_name',
16 | message: 'Enter the Custom Domain Name :',
17 | validate: helpers.validateUrl
18 | }).then(ans => {
19 | if (answers.isConfirm) {
20 | helpers.generateKeys(answers.username, ans.domain_name, 'generate');
21 | } else {
22 | helpers.generateKeys(answers.username, ans.domain_name, 'print');
23 | }
24 | })
25 | }
26 | if (answers.domain != 'custom_domain') {
27 | if (answers.isConfirm) {
28 | helpers.generateKeys(answers.username, domain, 'generate');
29 | } else {
30 | helpers.generateKeys(answers.username, domain, 'print');
31 | }
32 | }
33 | });
34 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2018 Gururaj Dharani( Pixelbuster )
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.
22 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | # Runtime data
9 | pids
10 | *.pid
11 | *.seed
12 | *.pid.lock
13 |
14 | # Directory for instrumented libs generated by jscoverage/JSCover
15 | lib-cov
16 |
17 | # Coverage directory used by tools like istanbul
18 | coverage
19 |
20 | # nyc test coverage
21 | .nyc_output
22 |
23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24 | .grunt
25 |
26 | # Bower dependency directory (https://bower.io/)
27 | bower_components
28 |
29 | # node-waf configuration
30 | .lock-wscript
31 |
32 | # Compiled binary addons (https://nodejs.org/api/addons.html)
33 | build/Release
34 |
35 | # Dependency directories
36 | node_modules/
37 | jspm_packages/
38 |
39 | # Typescript v1 declaration files
40 | typings/
41 |
42 | # Optional npm cache directory
43 | .npm
44 |
45 | # Optional eslint cache
46 | .eslintcache
47 |
48 | # Optional REPL history
49 | .node_repl_history
50 |
51 | # Output of 'npm pack'
52 | *.tgz
53 |
54 | # Yarn Integrity file
55 | .yarn-integrity
56 |
57 | # dotenv environment variables file
58 | .env
59 |
60 | # next.js build output
61 | .next
62 |
63 | # Local config
64 | config.js
65 | a.json
66 | .envrc
67 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://opensource.org/licenses/MIT)
2 | [](https://badge.fury.io/js/ssh-generator)
3 | [](https://github.com/ellerbrock/open-source-badges/)
4 |
5 | # SSH Generator
6 |
7 | Simple tool to generate ssh keys. Every time when i used to create ssh keys it generally took at least 10mins as a beginner. It will not take more than 2mins to create your ssh keys using this.
8 |
9 |

10 |
11 | Built to save 5mins of life 👌 !
12 |
13 | > If you think so, support me with a `star` and a `follow` 😘
14 |
15 | ## Usage
16 |
17 | With [npm](https://npmjs.org/) installed, run
18 |
19 | ```
20 | npm install -g ssh-generator
21 | ```
22 |
23 | ### Create your ssh keys with SSH Generator
24 |
25 | ```
26 | ssh-generator
27 | ```
28 |
29 | Select one of the three big git services for which you want to create your keys for. Or select custom to create keys for custom domains.
30 |
31 |
32 | ## Why ?
33 |
34 | As mentioned above it generally took at least 10-15mins for me to create those keys and get them up and running. Post searching for the steps again and again. This shouldn't take more than a minute to create your ssh keys.
35 |
36 | ## Built With
37 |
38 | * [Inquirer](https://github.com/SBoudrias/Inquirer.js) - Interactive CLI user interface.
39 | * [npm](https://www.npmjs.com/) - Package manager
40 |
41 | ## Roadmap
42 |
43 | * List all the keys in local and specific service.
44 | * update keys to github, bitbucket and gitlab respectively with users authentication
45 | * -- Suggestions? DM me on twitter [Gururaj](https://twitter.com/Gururaj15)
46 |
47 | ## Contributing
48 |
49 | Please read [CONTRIBUTING.md](CONTRIBUTING.MD) for details on our code of conduct, and the process for submitting pull requests to us.
50 |
51 | ## Authors
52 |
53 | * **Gururaj Dharani** - *Initial work* - [Gururaj26](https://github.com/Gururaj26)
54 |
55 | ## License
56 |
57 | This project is licensed under the MIT License - see the [LICENSE.md](LICENSE) file for details
58 |
59 | ## Acknowledgments
60 |
61 | * Hat tip to anyone whose code was used
62 |
--------------------------------------------------------------------------------
/helpers.js:
--------------------------------------------------------------------------------
1 | const chalkPipe = require('chalk-pipe')
2 | const constants = require('./constants.js')
3 | const seperator = constants.seperator
4 | const urlRegex = constants.urlRegex
5 | const thanksDecorator = constants.thanksDecorator
6 | const exec = require('child_process').exec
7 | const fs = require('fs');
8 | var os = require('os');
9 | const path = require('path')
10 |
11 | module.exports = {
12 | validateUrl: function(name) {
13 | const exp = urlRegex;
14 | const regex = new RegExp(exp);
15 | const isValid = name.match(regex);
16 | return (isValid ? true : false) || '~ Url is not valid'
17 | },
18 | validateName: function(name){
19 | const isValid = (name !== '');
20 | return isValid || '~ Username is required';
21 | },
22 | updateConfig: function(username, domain){
23 | const currentUser = os.userInfo().username;
24 | const configPath = `${ path.parse(process.cwd()).root + 'Users/' + currentUser + '/.ssh/config'}`;
25 | const host = `${'Host '+ username + '-' + domain}`;
26 | const hostName = `${'HostName '+ domain}`
27 | const identityFile = `${'IdentityFile ~/.ssh/' + username + '-' + domain}`;
28 | const config = `${'\r\n' + host + '\r\n' + ' ' + hostName + '\r\n' + ' ' + identityFile}`;
29 | fs.open(configPath, "a+", function(error, fd) {
30 | if (error) {
31 | console.error("open error: " + error.message);
32 | } else {
33 | fs.appendFile(fd, config, function (err) {
34 | if (err) throw err;
35 | console.log(seperator + 'Saved SSH to config file !' + seperator + thanksDecorator);
36 | process.exit(1);
37 | });
38 | }
39 | });
40 | },
41 | generateKeys: function(username, domain, type) {
42 | let exp = 'ssh-keygen -t rsa -b 4096 -f ~/.ssh/' + username + '-' + domain + ' ' + '-C' + ' ' + '"' + username + '-' + domain + '"';
43 | let printExp = `${'cat ~/.ssh/' + username + '-' + domain + '.pub'}`;
44 | if (type == 'print') {
45 | console.log(seperator + 'Paste this to create your ssh keys:' + seperator, chalkPipe('orange')(exp));
46 | } else {
47 | let child = exec(exp);
48 | child.stdout.on('data', function(data) {
49 | console.log('stdout: ' + data);
50 | let subchild = exec(printExp);
51 | subchild.stdout.on('data', function(data) {
52 | console.log(seperator + 'Freshly baked key: Ready to be served !' + seperator + chalkPipe('orange')(data));
53 | module.exports.updateConfig(username, domain);
54 | });
55 | subchild.stderr.on('data', function(data) {
56 | console.log('stdout: ' + data);
57 | });
58 | subchild.on('close', function(code) {
59 | console.log('closing code: ' + code);
60 | });
61 | });
62 | child.stderr.on('data', function(data) {
63 | console.log('stdout: ' + data);
64 | });
65 | child.on('close', function(code) {
66 | console.log('closing code: ' + code);
67 | });
68 | }
69 | }
70 | };
71 |
--------------------------------------------------------------------------------
/CONTRIBUTING.MD:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | When contributing to this repository, please first discuss the change you wish to make via issue,
4 | email, or any other method with the owners of this repository before making a change.
5 |
6 | Please note we have a code of conduct, please follow it in all your interactions with the project.
7 |
8 | ## Pull Request Process
9 |
10 | 1. Ensure any install or build dependencies are removed before the end of the layer when doing a
11 | build.
12 | 2. Update the README.md with details of changes to the interface, this includes new environment
13 | variables, exposed ports, useful file locations and container parameters.
14 | 3. Increase the version numbers in any examples files and the README.md to the new version that this
15 | Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/).
16 | 4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you
17 | do not have permission to do that, you may request the second reviewer to merge it for you.
18 |
19 | ## Code of Conduct
20 |
21 | ### Our Pledge
22 |
23 | In the interest of fostering an open and welcoming environment, we as
24 | contributors and maintainers pledge to making participation in our project and
25 | our community a harassment-free experience for everyone, regardless of age, body
26 | size, disability, ethnicity, gender identity and expression, level of experience,
27 | nationality, personal appearance, race, religion, or sexual identity and
28 | orientation.
29 |
30 | ### Our Standards
31 |
32 | Examples of behavior that contributes to creating a positive environment
33 | include:
34 |
35 | * Using welcoming and inclusive language
36 | * Being respectful of differing viewpoints and experiences
37 | * Gracefully accepting constructive criticism
38 | * Focusing on what is best for the community
39 | * Showing empathy towards other community members
40 |
41 | Examples of unacceptable behavior by participants include:
42 |
43 | * The use of sexualized language or imagery and unwelcome sexual attention or
44 | advances
45 | * Trolling, insulting/derogatory comments, and personal or political attacks
46 | * Public or private harassment
47 | * Publishing others' private information, such as a physical or electronic
48 | address, without explicit permission
49 | * Other conduct which could reasonably be considered inappropriate in a
50 | professional setting
51 |
52 | ### Our Responsibilities
53 |
54 | Project maintainers are responsible for clarifying the standards of acceptable
55 | behavior and are expected to take appropriate and fair corrective action in
56 | response to any instances of unacceptable behavior.
57 |
58 | Project maintainers have the right and responsibility to remove, edit, or
59 | reject comments, commits, code, wiki edits, issues, and other contributions
60 | that are not aligned to this Code of Conduct, or to ban temporarily or
61 | permanently any contributor for other behaviors that they deem inappropriate,
62 | threatening, offensive, or harmful.
63 |
64 | ### Scope
65 |
66 | This Code of Conduct applies both within project spaces and in public spaces
67 | when an individual is representing the project or its community. Examples of
68 | representing a project or community include using an official project e-mail
69 | address, posting via an official social media account, or acting as an appointed
70 | representative at an online or offline event. Representation of a project may be
71 | further defined and clarified by project maintainers.
72 |
73 | ### Enforcement
74 |
75 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
76 | reported by contacting the project team at [INSERT EMAIL ADDRESS]. All
77 | complaints will be reviewed and investigated and will result in a response that
78 | is deemed necessary and appropriate to the circumstances. The project team is
79 | obligated to maintain confidentiality with regard to the reporter of an incident.
80 | Further details of specific enforcement policies may be posted separately.
81 |
82 | Project maintainers who do not follow or enforce the Code of Conduct in good
83 | faith may face temporary or permanent repercussions as determined by other
84 | members of the project's leadership.
85 |
86 | ### Attribution
87 |
88 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
89 | available at [http://contributor-covenant.org/version/1/4][version]
90 |
--------------------------------------------------------------------------------