This is a creation in Article, where the information may have evolved or changed.
git clone https://github.com/golang/crypto.git, copy to the golang.org/x/directory.
Often used to establish an SSH connection to send a command, but sometimes need to impersonate the SSH client function, that is, directly connected to the remote host has been operating: (http://www.zhihu.com/question/30368538/answer/47835043)
Package Mainimport ("Golang.org/x/crypto/ssh" "Log" "OS"Func Main () {CE:= Func (err error, MSGstring) { ifErr! =Nil {log. Fatalf ("%s Error:%v", MSG, err)} } client, err:= ssh. Dial ("TCP","172.16.116.200:22", &ssh. clientconfig{User:"Root", Auth: []ssh. Authmethod{ssh. Password ("^two^ten=1024$")}, CE (Err,"Dial") session, err:=client. NewSession () CE (err,"New Session") Defer session. Close () session. Stdout=OS. Stdout session. Stderr=OS. Stderr session. Stdin=OS. Stdin modes:=ssh. terminalmodes{ssh. ECHO:0, SSH. Tty_op_ispeed:14400, SSH. Tty_op_ospeed:14400,} Err= Session. Requestpty ("xterm", -, the, modes) CE (err,"Request Pty") Err=session. Shell () CE (err,"Start Shell") Err=session. Wait () CE (err,"return")}
The actual use of defects, through the tab completion is not displayed correctly. or use the shell directly to write it, simple and practical:
#!/usr/bin/ssh root@122.116. 16.200 "password: " "123456\r" Interact