Comments (4)
from ssh.
The code follows:
package main
import (
"net"
"time"
"github.com/log"
"golang.org/x/crypto/ssh"
)
func main() {
UserName, Password := "root", "******"
ip_port := "**.**.**.**:22"
PassWd := []ssh.AuthMethod{ssh.Password(Password)}
Conf := ssh.ClientConfig{
User: UserName,
Auth: PassWd,
Timeout: time.Duration(20) * time.Second,
HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
return nil
},
}
sshClient, err := ssh.Dial("tcp", ip_port, &Conf)
if nil != err {
log.Error("ssh Dial failed")
return
}
session, err := sshClient.NewSession()
if nil != err {
log.Error("sshClient NewSession failed")
return
}
defer session.Close()
err = session.Run("/ushell")
// err = session.Run("/ushell;passwd")
// output, _ := session.Output("/ushell") //the output is:
//-> Please input password!
//->
//-> Error password!!
//-> Please input password!
//->
//-> Error password!!
//-> Please input password!
//->
//-> Error password!!
//-> Input password exceed 3 times ushell exit
}
from ssh.
from ssh.
It may not be very clear if you’re not used to working with SSH, but the Session object provided by this library is meant to be an extension of the gossh.Channel type. Because we expect things to be built on top of this, you need to tell the library what to do with IO. In this instance it means, handling the Channel.Read, Channel.Write and possibly even Channel.StderrPipe properly.
When you call session.Run(“./shell”) it’s running the command, but because Stdin isn’t set up, it’s reading from the channel and instantly seeing EOF.
Take a look at the example under https://godoc.org/golang.org/x/crypto/ssh#Channel to see how they set up Stdout. Something similar can be used for Stdin.
Good luck!
from ssh.
Related Issues (20)
- Ssh HOT 2
- shell/exec example HOT 7
- UsXAEwmfjWgURwmAZq23LfwB HOT 1
- Client automatically disconnects after some time HOT 1
- ssh
- Question - Compare ~/.ssh/id_rsa.pub and session.Publickey()
- Using ForwardAgentConnections for creating a "jump host" HOT 1
- Problem with non-interactive command handle HOT 1
- Remote port forwarding HOT 2
- ssh-publickey: sign_and_send_pubkey: no mutual signature supported
- [CVE-2023-48795] Using SSH Protocol Version Vulnerable to MITM HOT 1
- Windows - Process keeps running when stdin is set
- SSH HOT 1
- Support gossh NoClientAuthCallback
- Multi-protocol contribution tcp connection problem
- How to wait for Ctrl+C (session.Signals does not work as expected) HOT 2
- SSH
- Limiting traffic sent via tcp forward channel
- slack link doesn't work
- Intercept remote port forwarding connections and filter out by IP HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ssh.