This package acts as the core for an ssh client written in go
Made using data from packages:
- 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 this package in your repository
go get github.com/misha-ssh/kernelYou 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
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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}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 devicePassword- 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 deviceType- there is only one connection type so far -connect.TypeSSHCreatedAt- the creation time is filled in manuallyUpdatedAt- the update time is filled in manuallySshOptions- this is a structure with additional fields for creating software -connect.TypeSSHPort- the port is filled in manuallyPrivateKey- the path along with the name of the private keyPassphrase- 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: "",
},
}
}for local testing, you can raise your ssh servers - there are three types of them.
- password connection
to run, write the command:
make up-sshto install and remove the server:
make down-sshServer accesses:
login- rootaddress- localhostpassword- passwordport- 22
- connect with a private key
to run, write the command:
make up-ssh-keyto install and remove the server:
make down-ssh-keyServer accesses:
login- rootaddress- localhostprivate key- ./dockerkeyport- 22
- connecting via a non-standard port
to run, write the command:
make up-ssh-portto install and remove the server:
make down-ssh-portServer accesses:
login- rootaddress- localhostpassword- passwordport- 2222
- connect with a private key with passphrase
to run, write the command:
make up-ssh-key-passto install and remove the server:
make down-ssh-key-passServer accesses:
login- rootaddress- localhostprivate key- ./dockerkeyWithPassport- 22passphrase- password
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 directoryTheme- The theme is an application, there is no implementation at this stage.DirectionPrivateKeys- the name of the directory where the keys will be savedFilenameConnections- the name of the connection fileFilenameConfig- the name of the file with the application configsNameServiceCryptKey- the names of the service that will store the private key for encryptionTypeConsoleLogger- type for console loggingTypeStorageLogger- the type for logging to a fileTypeCombinedLogger- 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 implementationLogger- stores the type of application logging
You can run the command for testing after the step with local installation
The command to launch the linter:
make lintRun Unit tests:
make testsRun test coverage:
make test-coverageRun test e2e:
make tests-integrationWe appreciate your support and look forward to making our product even better with your help!