-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 489e3a9
Showing
450 changed files
with
216,453 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Go parameters | ||
GOCMD=go | ||
GOBUILD=$(GOCMD) build | ||
GOCLEAN=$(GOCMD) clean | ||
BINARY_DIR=bin | ||
BUILD_FLAGS=-v | ||
|
||
ifeq ($(OS),Windows_NT) | ||
CLEAN_CMD = del /Q $(BINARY_DIR)\*.* && rmdir /S /Q $(BINARY_DIR) | ||
else | ||
CLEAN_CMD = rm -rf $(BINARY_DIR) | ||
endif | ||
|
||
# Targets | ||
all: windows | ||
|
||
windows: | ||
$(GOBUILD) $(BUILD_FLAGS) -o $(BINARY_DIR)/ssm.exe main.go | ||
|
||
clean: | ||
$(CLEAN_CMD) | ||
|
||
.PHONY: clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# SSM - THE SECURE SHELL MANAGER | ||
|
||
``` | ||
_____ _____ _____ | ||
| __| __| | | ||
|__ |__ | | | | | ||
|_____|_____|_|_|_| | ||
SSM - THE SECURE SHELL MANAGER | ||
- Elliot | ||
``` | ||
|
||
## Directory structure | ||
|
||
``` | ||
/home/elliot/.ssh | ||
├── config * | ||
├── config.d * | ||
│ ├── compute | ||
│ └── homelab | ||
├── known_hosts | ||
├── id_rsa // private key ** | ||
└── id_rsa.pub // public key ** | ||
``` | ||
> `*` - Required | ||
> `**` SSH keys are not required if you use password authorization | ||
> SSH keys can be generated with [ssh-keygen](https://www.ssh.com/academy/ssh/config) | ||
## Config file `~/.ssh/config` | ||
|
||
``` | ||
# WORK SERVERS | ||
Include config.d/compute | ||
# HOME SERVERS | ||
Include config.d/homelab | ||
``` | ||
|
||
## Example file in config.d `~/.ssh/config.d/compute` | ||
|
||
``` | ||
Host compute | ||
HostName 192.168.0.110 | ||
IdentityFile ~/.ssh/id_rsa | ||
User ubuntu | ||
Port 4444 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"strings" | ||
|
||
"github.com/elliot40404/ssm/pkg/model" | ||
"github.com/elliot40404/ssm/pkg/utils" | ||
"github.com/manifoldco/promptui" | ||
"github.com/urfave/cli/v2" | ||
"golang.org/x/exp/slices" | ||
) | ||
|
||
func Add(cCtx *cli.Context) error { | ||
var name string | ||
for { | ||
name = utils.BasicPrompt("Name your config", false) | ||
if !checkExisting(name) { | ||
break | ||
} | ||
fmt.Println("Config with same name already exists") | ||
} | ||
// TODO: ADD CONFIG VALIDATION | ||
var config model.Config | ||
config.Name = name | ||
config.Hostname = utils.BasicPrompt("Hostname", false) | ||
config.User = utils.BasicPrompt("User", false) | ||
config.Port = utils.BasicPrompt("Port (Enter to use Default 22)", true) | ||
if config.Port == "" { | ||
config.Port = "22" | ||
} | ||
usekey := askYesNo("Use SSH Key [Y|n]: ", "Y") | ||
if usekey { | ||
result := selectMenu("Select SSH Key", utils.GetSSHKeys(), true) | ||
if result == "Add New" { | ||
config.SshKey = utils.BasicPrompt("Full path to ssh key", false) | ||
} else { | ||
config.SshKey = "~/.ssh/" + result | ||
} | ||
} | ||
result := selectMenu("Select Category", utils.GetCategories(), true) | ||
if result == "Add New" { | ||
config.Category = utils.BasicPrompt("Enter New Category (without #)", false) | ||
} else { | ||
config.Category = result | ||
} | ||
config.Save(usekey) | ||
return nil | ||
} | ||
|
||
func checkExisting(name string) bool { | ||
return slices.Contains(utils.GetSSHConfigs(false), name) | ||
} | ||
|
||
func selectMenu(promptText string, items []string, addNew bool) string { | ||
options := items | ||
if addNew { | ||
options = append(options, "Add New") | ||
} | ||
prompt := promptui.Select{ | ||
Label: promptText, | ||
Items: options, | ||
HideSelected: true, | ||
} | ||
_, result, err := prompt.Run() | ||
if err != nil { | ||
log.Fatal("Something went wrong") | ||
} | ||
return result | ||
} | ||
|
||
func askYesNo(promptText string, defaultValue string) bool { | ||
fmt.Print(promptText) | ||
var input string | ||
_, err := fmt.Scanln(&input) | ||
if err != nil { | ||
fmt.Println("Error reading input:", err) | ||
return false | ||
} | ||
// Use the default value if input is empty | ||
if strings.TrimSpace(input) == "" { | ||
input = defaultValue | ||
} | ||
// Convert input to uppercase for comparison | ||
input = strings.ToUpper(input) | ||
return input == "Y" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/elliot40404/ssm/pkg/utils" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func List(cCtx *cli.Context) error { | ||
for idx, name := range utils.GetSSHConfigs(false) { | ||
if cCtx.Bool("count") { | ||
fmt.Printf("%v. %v\n", idx+1, name) | ||
} else { | ||
fmt.Printf("%v\n", name) | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module github.com/elliot40404/ssm | ||
|
||
go 1.20 | ||
|
||
require ( | ||
github.com/manifoldco/promptui v0.9.0 | ||
github.com/urfave/cli/v2 v2.25.7 | ||
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df | ||
) | ||
|
||
require ( | ||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect | ||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect | ||
github.com/russross/blackfriday/v2 v2.1.0 // indirect | ||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect | ||
golang.org/x/sys v0.1.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE= | ||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= | ||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8= | ||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= | ||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8= | ||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= | ||
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= | ||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | ||
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA= | ||
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg= | ||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= | ||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||
github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs= | ||
github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ= | ||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= | ||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= | ||
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME= | ||
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= | ||
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= | ||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
|
||
"github.com/elliot40404/ssm/commands" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func main() { | ||
app := &cli.App{ | ||
Name: "ssm", | ||
Usage: "ssh config manager", | ||
Version: "0.1.0", | ||
Commands: []*cli.Command{ | ||
{ | ||
Name: "list", | ||
Aliases: []string{"ls"}, | ||
Usage: "list available ssh configs", | ||
Action: commands.List, | ||
Flags: []cli.Flag{ | ||
&cli.BoolFlag{ | ||
Name: "count", | ||
Value: false, | ||
Usage: "print serial numbers", | ||
Aliases: []string{"c"}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: "add", | ||
Usage: "add new ssh config", | ||
Action: commands.Add, | ||
}, | ||
}, | ||
} | ||
|
||
if err := app.Run(os.Args); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package model | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/elliot40404/ssm/pkg/utils" | ||
) | ||
|
||
type Config struct { | ||
Name string | ||
Hostname string | ||
Port string | ||
User string | ||
Category string | ||
SshKey string | ||
} | ||
|
||
func (c *Config) Save(useKey bool) { | ||
var config string | ||
if useKey { | ||
config = fmt.Sprintf("Host %v\n HostName %v\n IdentityFile %v\n User %v\n Port %v", c.Name, c.Hostname, c.SshKey, c.User, c.Port) | ||
} else { | ||
config = fmt.Sprintf("Host %v\n HostName %v\n User %v\n Port %v", c.Name, c.Hostname, c.User, c.Port) | ||
} | ||
utils.CreateConfig(c.Name, config) | ||
utils.LinkConfig(c.Name, c.Category) | ||
fmt.Println("Config saved! You can now access it using: ssh", c.Name) | ||
} |
Oops, something went wrong.