Skip to content

Instantly share code, notes, and snippets.

@bambuchaAdm
Created December 8, 2013 16:14
Show Gist options
  • Select an option

  • Save bambuchaAdm/7859619 to your computer and use it in GitHub Desktop.

Select an option

Save bambuchaAdm/7859619 to your computer and use it in GitHub Desktop.
Go ssh error.
OpenSSH_6.4, OpenSSL 1.0.1e 11 Feb 2013
debug1: Reading configuration data /home/bambucha/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to localhost [::1] port 2223.
debug1: Connection established.
debug1: identity file /home/bambucha/.ssh/id_rsa type 1
debug1: identity file /home/bambucha/.ssh/id_rsa-cert type -1
debug1: identity file /home/bambucha/.ssh/id_dsa type -1
debug1: identity file /home/bambucha/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.4p1-hpn14v2
debug1: Remote protocol version 2.0, remote software version Go
debug1: no match: Go
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: AUTH STATE IS 0
debug1: REQUESTED ENC.NAME is 'aes128-ctr'
debug1: kex: server->client aes128-ctr hmac-sha1 none
debug1: REQUESTED ENC.NAME is 'aes128-ctr'
debug1: kex: client->server aes128-ctr hmac-sha1 none
debug1: sending SSH2_MSG_KEXDH_INIT
debug1: expecting SSH2_MSG_KEXDH_REPLY
debug1: Server host key: RSA 47:4f:a4:56:24:67:56:61:74:f8:7c:1e:b9:0c:4b:54
debug1: Host '[localhost]:2223' is known and matches the RSA host key.
debug1: Found key in /home/bambucha/.ssh/known_hosts:101
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: password
debug1: Next authentication method: password
testuser@localhost's password:
debug1: Single to Multithread CTR cipher swap - client request
debug1: Authentication succeeded (password).
Authenticated to localhost ([::1]:2223).
debug1: Final hpn_buffer_size = 131072
debug1: HPN Disabled: 0, HPN Buffer Size: 131072
debug1: channel 0: new [client-session]
debug1: Enabled Dynamic Window Scaling
debug1: Entering interactive session.
debug1: need rekeying
debug1: SSH2_MSG_KEXINIT sent
debug1: rekeying in progress
debug1: SSH2_MSG_KEXINIT received
debug1: AUTH STATE IS 1
debug1: REQUESTED ENC.NAME is 'aes128-ctr'
debug1: kex: server->client aes128-ctr hmac-sha1 none
debug1: REQUESTED ENC.NAME is 'aes128-ctr'
debug1: kex: client->server aes128-ctr hmac-sha1 none
debug1: sending SSH2_MSG_KEXDH_INIT
debug1: expecting SSH2_MSG_KEXDH_REPLY
Disconnecting: Protocol error: expected packet type 31, got 94
package main
import (
"fmt"
"io/ioutil"
"code.google.com/p/go.crypto/ssh"
"code.google.com/p/go.crypto/ssh/terminal"
)
func main(){
fmt.Println("Start serwera ssh")
config := &ssh.ServerConfig{
PasswordCallback: func(conn * ssh.ServerConn, user, pass string) bool {
return user == "testuser" && pass == "tiger"
},
}
private_bytes, err := ioutil.ReadFile("server_rsa")
if err != nil {
panic("Failed to read private key")
}
fmt.Println("Privet key readed")
private_key, err := ssh.ParsePrivateKey(private_bytes)
if err != nil {
panic("Error on parsing server private key")
}
fmt.Println("Private key paresed")
config.AddHostKey(private_key)
fmt.Println("Private key attached to server config")
listen, err := ssh.Listen("tcp", "0.0.0.0:2223", config)
if err != nil {
panic("Cannot create liste object")
}
fmt.Println("listen has bind to port and address")
sConn, err := listen.Accept()
if err != nil {
panic("Filed to accept incomming connection")
}
if err := sConn.Handshake(); err != nil {
panic("Handshake failed")
}
fmt.Println("Handshake compleate")
for {
channel, err := sConn.Accept()
if err != nil {
panic("Error on accept. " + err.Error())
}
fmt.Println(channel.ChannelType())
if channel.ChannelType() != "session" {
channel.Reject(ssh.UnknownChannelType, "unknown channel type")
continue
}
fmt.Println("Try to start new terminal")
term := terminal.NewTerminal(channel, "> ")
serverTerm := &ssh.ServerTerminal{
Term: term,
Channel: channel,
}
go func() {
defer channel.Close()
for {
line, err := serverTerm.ReadLine()
if err != nil {
break
}
fmt.Println(line)
}
}()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment