go.crypto/ssh server

1,070 views
Skip to first unread message

Vasiliy Tolstov

unread,
Dec 2, 2013, 2:57:23 AM12/2/13
to golan...@googlegroups.com
Hi All. if i want to use go.crypto/ssh for writing small ssh server,
and provide interactive terminal for end user (user used openssh
client). What i need to do?
I can run commands from users by exec.Command and get ourput. But for
interactive commands i need to pty.
how can i create pty and use it in golang ssh server?
Thanks!

--
Vasiliy Tolstov,
e-mail: v.to...@selfip.ru
jabber: va...@selfip.ru

agl

unread,
Dec 2, 2013, 12:29:32 PM12/2/13
to golan...@googlegroups.com
On Monday, December 2, 2013 2:57:23 AM UTC-5, Vasiliy Tolstov wrote:
Hi All. if i want to use go.crypto/ssh for writing small ssh server,
and provide interactive terminal for end user (user used openssh
client). What i need to do?
I can run commands from users by exec.Command and get ourput. But for
interactive commands i need to pty.
how can i create pty and use it in golang ssh server?
Thanks!


(Although note that the ssh/ package is likely to have major work done in the Go 1.3 timespan.) 


Cheers

AGL 

Vasiliy Tolstov

unread,
Dec 2, 2013, 1:29:51 PM12/2/13
to agl, golan...@googlegroups.com
2013/12/2 agl <a...@golang.org>:
> See http://godoc.org/code.google.com/p/go.crypto/ssh#example-Listen
>
> (Although note that the ssh/ package is likely to have major work done in
> the Go 1.3 timespan.)
>
>
> Cheers


Thanks. Exammple listen very good. But then i try to exec mc i can't
move keys up/down. I think that because readline usage in example...
But i may miss somethink more...

chend...@gmail.com

unread,
Oct 23, 2014, 5:19:27 AM10/23/14
to golan...@googlegroups.com
hello, 
  I'm writting small ssh server use pty, but I can not work out.
  So you can mail your ssh server code to me?
  Best Wish. Thank you very much



在 2013年12月2日星期一UTC+8下午3时57分23秒,Vasiliy Tolstov写道:

jpil...@gmail.com

unread,
Dec 1, 2014, 8:48:58 PM12/1/14
to golan...@googlegroups.com, chend...@gmail.com
+1

I think I've nearly got it, see the following gist: https://gist.github.com/jpillora/b480fde82bff51a06238

Though I'm getting "PTY allocation request failed on channel 0" when I connect to it

Any tips?

Dave Cheney

unread,
Dec 1, 2014, 9:29:52 PM12/1/14
to golan...@googlegroups.com, chend...@gmail.com, jpil...@gmail.com
Hmm, can you look at the log from the server's end ? It should be /var/log/secure or /var/log/auth.log from memory of the common places that distros set their syslog to.

Jaime Pillora

unread,
Dec 1, 2014, 9:40:08 PM12/1/14
to Dave Cheney, golang-nuts, chend...@gmail.com
Hi Dave, currently testing on Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-39-generic x86_64) – log/secure doesn’t exist and log/auth.log only contains contains the system sshd logs. I thought a crypto/ssh server was a complete implementation or does it depend on the system sshd? Also I seem to be able to log in okay, though maybe the crypto/ssh/terminal package is failing to get a pty, see https://gist.github.com/jpillora/b480fde82bff51a06238#comment-1347606


Dave Cheney

unread,
Dec 1, 2014, 9:48:42 PM12/1/14
to golan...@googlegroups.com
Os, my mistake, I thoght you were using the client against sshd. I'm not sure if or where the os would log an issue if a process couldn't allocate a new tty. Ada guess, have you run out of file descriptors?

Dave Cheney

unread,
Dec 1, 2014, 10:27:25 PM12/1/14
to golang-nuts
Ah, figured it out, the go ssh terminal doesn't support allocating a
pty (so no concept of screen size, raw vs cooked etc), by default
openssh will request a pty _unless_ you pass a command, ie

ssh someone@somewhere /bin/ls

Won't allocate a pty, you can check this by doing ssh somewhere top,
top will whinge because there isn't proper terminal control.

However, when there is no command supplies, ssh requests a shell
session, and a pty, this is what is failing. You can disable the
automatic pty setting with -T, or in .ssh/config, or a bunch of other
ways

% ssh foo@localhost -T -p 2022

foo@localhost's password:

> hello

hello

On Tue, Dec 2, 2014 at 1:48 PM, Dave Cheney <da...@cheney.net> wrote:
> Os, my mistake, I thoght you were using the client against sshd. I'm not sure if or where the os would log an issue if a process couldn't allocate a new tty. Ada guess, have you run out of file descriptors?
>
> --
> You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/rIWZIjsXoqg/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Rob Pike

unread,
Dec 1, 2014, 10:47:16 PM12/1/14
to Dave Cheney, golang-nuts
Wait, teletypes are finally gone so we need pseudo teletypes?

-rob


You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.

Dave Cheney

unread,
Dec 1, 2014, 10:49:58 PM12/1/14
to Rob Pike, golang-nuts
Gotta virtualize everything rob, this is the future.

Jaime Pillora

unread,
Dec 1, 2014, 10:50:01 PM12/1/14
to Dave Cheney, golang-nuts
Sorry, I’ve been just replying to Dave – for completeness:

$ sysctl fs.file-nr
fs.file-nr = 768 0 400048


[Dave reports that ssh/terminal doesn’t support allocating ptys]

ah I see, so it’s not supported, I’ll try mixing in https://github.com/kr/pty and report back - thanks dave





On Tue, Dec 2, 2014 at 1:48 PM, Dave Cheney <da...@cheney.net> wrote:
Os, my mistake, I thoght you were using the client against sshd. I'm not sure if or where the os would log an issue if a process couldn't allocate a new tty. Ada guess, have you run out of file descriptors?

Rob Pike

unread,
Dec 1, 2014, 10:57:25 PM12/1/14
to Dave Cheney, golang-nuts
If we're typing on teletypes, pseudo or otherwise, it may be the future but we are living in the past.

OK, I'll stop now. I started complaining about this long ago and nobody cared then, either.

-rob

jpil...@gmail.com

unread,
Dec 2, 2014, 4:08:58 AM12/2/14
to golan...@googlegroups.com
Thanks Dave, all working now https://gist.github.com/jpillora/b480fde82bff51a06238 (with window resizes too! give 'top' a try)

Dave Cheney

unread,
Dec 2, 2014, 4:34:42 AM12/2/14
to Jaime Pillora, golang-nuts
Awesome work.

I had a look at ssh/terminal to see if it should really be doing the
pty handling, but my impression is that facility is beyond the remit
of the terminal package.

With that said, this is the sort of knowledge that should be shared.
How much would I have to twist your arm to blog about this ? If you
don't have a convenient spot to blog this can I gratuitously plug the
Go Advent series we're running over at blog.gopheracademy.com ?

Cheers

Dave

Jaime Pillora

unread,
Dec 2, 2014, 6:09:10 AM12/2/14
to Dave Cheney, golang-nuts
I don’t have a blog myself, though I’d be happy to write up a few paragraphs on gopheracademy. Send through an email with the details and I’ll get on it.

Nick Craig-Wood

unread,
Dec 2, 2014, 8:46:03 AM12/2/14
to jpil...@gmail.com, golan...@googlegroups.com
On 02/12/14 09:08, jpil...@gmail.com wrote:
> https://gist.github.com/jpillora/b480fde82bff51a06238 (with window
> resizes too! give 'top' a try)

Very nice!

It seems to be leaving behind zombies. ps axf looked like this after 3
logins and exits

6772 pts/73 Sl+ 0:00 | | \_ ./go-sshd-example
6786 ? Zs 0:00 | | \_ [bash] <defunct>
6806 ? Zs 0:00 | | \_ [bash] <defunct>
6817 ? Zs 0:00 | | \_ [bash] <defunct>

--
Nick Craig-Wood <ni...@craig-wood.com> -- http://www.craig-wood.com/nick

Gyu-Ho Lee

unread,
Dec 2, 2014, 1:49:41 PM12/2/14
to golan...@googlegroups.com, da...@cheney.net, jpil...@gmail.com
Thanks! This happens to be the one that I need right now.

jpil...@gmail.com

unread,
Dec 2, 2014, 10:04:52 PM12/2/14
to golan...@googlegroups.com, jpil...@gmail.com
You need to call Wait() to reap the zombies.

Thanks Nick, Wait() did the trick – updated the gist
Reply all
Reply to author
Forward
0 new messages