Skip to content

Golang package for easy remote execution through SSH

Notifications You must be signed in to change notification settings

jniltinho/easyssh

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

easyssh

Description

Package easyssh provides a simple implementation of some SSH protocol features in Go. You can simply run command on remote server or upload a file even simple than native console SSH client. Do not need to think about Dials, sessions, defers and public keys...Let easyssh will be think about it!

Install

go get github.com/jniltinho/easyssh

So easy to use!

Run a command on remote server and get STDOUT output

package main

import (
	"github.com/jniltinho/easyssh"
)

func main() {
	// Create MakeConfig instance with remote username, server address and path to private key.
	ssh := &easyssh.MakeConfig{User: "user1", Server: "server.example.com", Password: "<user1password>"}

	// Call Run method with command you want to run on remote server.
	response, err := ssh.Run("ps ax")
	// Handle errors
	if err != nil {
		panic("Can't run remote command: " + err.Error())
	} else {
		print(response)
	}
}

Upload a file

Upload a file to remote server

package main

import (
	"github.com/jniltinho/easyssh"
)

func main() {
	// Create MakeConfig instance with remote username, server address and path to private key.
	ssh := &easyssh.MakeConfig{User: "user1", Server: "server.example.com", Password: "<user1password>"}

	// Call Scp method with file you want to upload to remote server.
	err := ssh.Scp("/home/linuxpro/GO/src/goclientssh.go")

	// Handle errors
	if err != nil {
		panic("Can't run remote command: " + err.Error())
	} else {
		println("success")

		response, _ := ssh.Run("ls -al goclientssh.go")
		print(response)
		
		// Move file
		ssh.Run("mv ~/goclientssh.go ~/GO/src/")
	}
}

SSH Error

panic: Can't run remote command: ssh: handshake failed: 
ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
## Change file: /etc/ssh/sshd_config
sed -i 's|PasswordAuthentication no|PasswordAuthentication yes|' /etc/ssh/sshd_config


## Or add the end of the file.
## Match address 192.168.1.0/24
##    PasswordAuthentication yes

## And restart sshd service
sudo service sshd restart

Thank

@hypersleep: Vladislav Spirenkov -> https://github.com/hypersleep/easyssh

About

Golang package for easy remote execution through SSH

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%