Skip to content

misha-ssh/kernel

Misha ssh - kernel

Go Report Card Go Docs Release Action Lint Action Tests Action Tests Integration Wakatime

This package acts as the core for an ssh client written in go

Made using data from packages:

📝 Features

  • Connection Management: Commands for creating, connecting, deleting, and updating your connection
  • Download & Upload files: Commands for working with sftp file transfer
  • Data encryption: Your connection is securely encrypted
  • Configurations: Possibility of connection configuration
  • The local environment There is an environment for testing the connection
  • Flexibility The ability to embed in any client on go

✨ Install

install this package in your repository

go get github.com/misha-ssh/kernel

📖 Examples & Usage

You will be provided with a list of commands that you can use in your projects

The code with the commands will be on the way - link

🔌 Connect

The command to connect to the remote server

package main

import (
	"github.com/misha-ssh/kernel/pkg/connect"
	"github.com/misha-ssh/kernel/pkg/kernel"
)

func main() {
	connection := &connect.Connect{...}

	err := kernel.Connect(connection)
	if err != nil {
		panic(err)
	}
}

🔌 Download

The command to connect to the remote server

this command downloads the file from the server

package main

import (
	"github.com/misha-ssh/kernel/pkg/connect"
	"github.com/misha-ssh/kernel/pkg/kernel"
)

func main() {
	connection := &connect.Connect{...}

	remoteFile := "/remote.txt"
	localFile := "~/local.txt"

	err := kernel.Download(connection, remoteFile, localFile)
	if err != nil {
		panic(err)
	}
}

🔌 Upload

The command to connect to the remote server

this command is to upload a file to a remote server

package main

import (
	"github.com/misha-ssh/kernel/pkg/connect"
	"github.com/misha-ssh/kernel/pkg/kernel"
)

func main() {
	connection := &connect.Connect{...}

	remoteFile := "/upload.txt"
	localFile := "/absolute/path/your_local_file.txt"

	err := kernel.Upload(connection, localFile, remoteFile)
	if err != nil {
		panic(err)
	}
}

✍️ Create

The command to create a connection

this command saves the connection to a file and goes through the dependency initialization cycle

package main

import (
	"github.com/misha-ssh/kernel/pkg/connect"
	"github.com/misha-ssh/kernel/pkg/kernel"
)

func main() {
	connection := &connect.Connect{...}

	err := kernel.Create(connection)
	if err != nil {
		panic(err)
	}
}

🪄 Update

The command to update the connection

This command also updates the connection data if you need to resave the private key

package main

import (
	"github.com/misha-ssh/kernel/pkg/connect"
	"github.com/misha-ssh/kernel/pkg/kernel"
)

func main() {
	connection := &connect.Connect{...}

	err := kernel.Update(connection, "test")
	if err != nil {
		panic(err)
	}
}

🆑 Delete

The command to delete the connection

This command removes the connection from the file and also deletes the private key if it has been saved

package main

import (
	"github.com/misha-ssh/kernel/pkg/connect"
	"github.com/misha-ssh/kernel/pkg/kernel"
)

func main() {
	connection := &connect.Connect{...}

	err := kernel.Delete(connection)
	if err != nil {
		panic(err)
	}
}

📝 List

The command to get a list of connections

This command will list the connections from the previously created connections

package main

import (
	"fmt"

	"github.com/misha-ssh/kernel/pkg/kernel"
)

func main() {
	connections, err := kernel.List()
	if err != nil {
		panic(err)
	}

	fmt.Println(connections)
}

🖥 Struct Connection

This structure describes our connection

We pass this structure to the commands:

  • Connect
  • Create
  • Update
  • Delete

Description of fields:

  • Alias - unique name (we use it when selecting an exception from the list and create unique connections to identify them)
  • Login - the user's login on the remote device
  • Password - if you have a password connection, then fill in this field, if with a key, then leave an empty line.
  • Address - the address of the remote device
  • Type - there is only one connection type so far - connect.TypeSSH
  • CreatedAt - the creation time is filled in manually
  • UpdatedAt - the update time is filled in manually
  • SshOptions - this is a structure with additional fields for creating software - connect.TypeSSH
  • Port - the port is filled in manually
  • PrivateKey - the path along with the name of the private key
  • Passphrase - the pass for private key
package main

import (
	"time"

	"github.com/misha-ssh/kernel/pkg/connect"
)

func main() {
	connection := &connect.Connect{
		Alias:     "test",
		Login:     "root",
		Password:  "password",
		Address:   "localhost",
		Type:      connect.TypeSSH,
		CreatedAt: time.Now().Format(time.RFC3339),
		UpdatedAt: time.Now().Format(time.RFC3339),
		SshOptions: &connect.SshOptions{
			Port:       22,
			PrivateKey: "/path/to/private/key",
			Passphrase: "",
		},
	}
}

🤖 Run ssh server

for local testing, you can raise your ssh servers - there are three types of them.

  1. password connection

to run, write the command:

make up-ssh

to install and remove the server:

make down-ssh

Server accesses:

  • login - root
  • address - localhost
  • password - password
  • port - 22
  1. connect with a private key

to run, write the command:

make up-ssh-key

to install and remove the server:

make down-ssh-key

Server accesses:

  • login - root
  • address - localhost
  • private key - ./dockerkey
  • port - 22
  1. connecting via a non-standard port

to run, write the command:

make up-ssh-port

to install and remove the server:

make down-ssh-port

Server accesses:

  • login - root
  • address - localhost
  • password - password
  • port - 2222
  1. connect with a private key with passphrase

to run, write the command:

make up-ssh-key-pass

to install and remove the server:

make down-ssh-key-pass

Server accesses:

  • login - root
  • address - localhost
  • private key - ./dockerkeyWithPass
  • port - 22
  • passphrase - password

🔖 Description variable

The variables that the application uses are located here:

App values (the values that are used in the application and also in the config):

  • AppName - project name & project directory
  • Theme - The theme is an application, there is no implementation at this stage.
  • DirectionPrivateKeys - the name of the directory where the keys will be saved
  • FilenameConnections - the name of the connection file
  • FilenameConfig - the name of the file with the application configs
  • NameServiceCryptKey - the names of the service that will store the private key for encryption
  • TypeConsoleLogger - type for console logging
  • TypeStorageLogger - the type for logging to a file
  • TypeCombinedLogger - type for all types of logging

Config keys (these keys are located in the application configuration):

  • Theme - stores the application's theme, in this case there is no implementation
  • Logger - stores the type of application logging

🧪 Testing

You can run the command for testing after the step with local installation

The command to launch the linter:

make lint

Run Unit tests:

make tests

Run test coverage:

make test-coverage

Run test e2e:

make tests-integration

🤝 Feedback

We appreciate your support and look forward to making our product even better with your help!

@Denis Korbakov

About

⚡️ The core for ssh client on go

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •