17912 [Solved] Solution for lack of TTY (giving SSH problems) when using jexec to access jail=>tmux! - The FreeBSD Forums
The FreeBSD Forums  

Go Back   The FreeBSD Forums > Base System > General

General General questions about the FreeBSD operating system. Ask here if your question does not fit elsewhere.

Reply
 
Thread Tools Display Modes
  #1  
Old December 8th, 2010, 15:33
hopla hopla is offline
Junior Member
 
Join Date: Nov 2008
Posts: 34
Thanks: 11
Thanked 3 Times in 2 Posts
Default Solution for lack of TTY (giving SSH problems) when using jexec to access jail=>tmux!

Hi there!

You know the problem when you want the ssh from within a jail after you jexec'ed into it?

I mean this:
Code:
@host# jexec <jid> <shell>
@jail# ssh user@host
Host key verification failed.
or this:

Code:
@host# jexec <jid> <shell>
@jail# ssh user@host
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
Or also when using screen:
Code:
@host# jexec <jid> <shell>
@jail# screen
Cannot access '/dev/pts/11': No such file or directory
As you might know, that's because you don't have a TTY when you jexec into a jail. Possible solutions for this are:

* using PKI auth (but this only solves the problem for SSH and not for other commands that need a TTY)
* running sshd in the jail and logging into the jail via SSH (but what if you want to keep your jail very secure and don't want to run sshd?)

I have now found a much better solution, that I haven't seen mentioned anywhere yet, so I thought I might want to share it with you guys:

/usr/ports/sysutils/tmux

It's a terminal multiplexer like screen, but unlike screen it works even when you jexec'ed into a jail! And because its a terminal multiplexer, you get a TTY!

Now you can do this:

Code:
@host# jexec <jid> <shell>
@jail# tmux
@jail# ssh user@host
user@host's password:
I don't know what tmux's secret sauce is, but its awesome!

Last edited by hopla; December 8th, 2010 at 16:17.
Reply With Quote
The Following 2 Users Say Thank You to hopla For This Useful Post:
graudeejs (December 8th, 2010), idownes (June 17th, 2011)
  #2  
Old December 8th, 2010, 15:40
SirDice's Avatar
SirDice SirDice is offline
Moderator
 
Join Date: Nov 2008
Location: Rotterdam, Netherlands
Posts: 13,702
Thanks: 47
Thanked 2,022 Times in 1,861 Posts
Default

# jexec <jid> /usr/bin/su - works for me.
__________________
Senior UNIX Engineer at Unix Support Nederland
Experience is something you don't get until just after you need it.
Reply With Quote
  #3  
Old December 8th, 2010, 15:42
graudeejs's Avatar
graudeejs graudeejs is online now
Style(9) Addict
 
Join Date: Nov 2008
Location: Riga, Latvia
Posts: 4,522
Thanks: 422
Thanked 607 Times in 475 Posts
Default

I'm using tmux for quite some time now...
Never thought of running tmux in jail...

Thanks, I already see where I could use this
Reply With Quote
  #4  
Old December 8th, 2010, 15:43
graudeejs's Avatar
graudeejs graudeejs is online now
Style(9) Addict
 
Join Date: Nov 2008
Location: Riga, Latvia
Posts: 4,522
Thanks: 422
Thanked 607 Times in 475 Posts
Default

Quote:
Originally Posted by SirDice View Post
# jexec <jid> /usr/bin/su - works for me.
Doesn't work all that well. Can't run mksh in jail (Unlike with tmux)
Reply With Quote
  #5  
Old December 8th, 2010, 15:48
hopla hopla is offline
Junior Member
 
Join Date: Nov 2008
Posts: 34
Thanks: 11
Thanked 3 Times in 2 Posts
Default

Quote:
Originally Posted by SirDice View Post
# jexec <jid> /usr/bin/su - works for me.
I almost had an even bigger WOW moment, but just like killasmurf86 it doesn't seem to work for me:

Code:
# jexec 8 /usr/bin/su -
# ssh user@host
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
Reply With Quote
  #6  
Old December 8th, 2010, 15:55
SirDice's Avatar
SirDice SirDice is offline
Moderator
 
Join Date: Nov 2008
Location: Rotterdam, Netherlands
Posts: 13,702
Thanks: 47
Thanked 2,022 Times in 1,861 Posts
Default

You need to generate a host key. Have a look at the /etc/rc.d/sshd script. Normally when it runs for the first time on a clean machine it'll generate the host keys. Without the host keys ssh isn't going to work.
__________________
Senior UNIX Engineer at Unix Support Nederland
Experience is something you don't get until just after you need it.
Reply With Quote
  #7  
Old December 8th, 2010, 16:05
hopla hopla is offline
Junior Member
 
Join Date: Nov 2008
Posts: 34
Thanks: 11
Thanked 3 Times in 2 Posts
Default

Quote:
Originally Posted by SirDice View Post
You need to generate a host key. Have a look at the /etc/rc.d/sshd script. Normally when it runs for the first time on a clean machine it'll generate the host keys. Without the host keys ssh isn't going to work.
I tested this on a jail where sshd was running. The jail most certainly has host keys. The host keys don't enter into it, it's the lack of a TTY that makes it fail.

It probably works for you because you have PKI auth set up?

See if you can run screen when you jexec into your jail. You will see the problem! Then run tmux and on top of that run screen and voila! Suddenly it works! (of course this example is silly and contrived, but perfectly illustrates the problem)

EDIT: on second thought, I think you are misunderstanding the problem on another level SirDice, maybe because the title of this post isn't quite accurate and because the sequence of commands in the examples are misleading... When I run jexec followed by another command, that command is run IN the jail, not on the host where I ran jexec. I will edit the title and examples.

Last edited by hopla; December 8th, 2010 at 16:13.
Reply With Quote
  #8  
Old December 8th, 2010, 16:25
SirDice's Avatar
SirDice SirDice is offline
Moderator
 
Join Date: Nov 2008
Location: Rotterdam, Netherlands
Posts: 13,702
Thanks: 47
Thanked 2,022 Times in 1,861 Posts
Default

Screen works for me, no problems there. I do seem to have the same ssh problem though. The error message kinda threw me off. But with -v it indeed shows that ssh fails because it cannot open a pty.
__________________
Senior UNIX Engineer at Unix Support Nederland
Experience is something you don't get until just after you need it.
Reply With Quote
  #9  
Old December 8th, 2010, 17:00
hopla hopla is offline
Junior Member
 
Join Date: Nov 2008
Posts: 34
Thanks: 11
Thanked 3 Times in 2 Posts
Default

Quote:
Originally Posted by SirDice View Post
Screen works for me, no problems there. I do seem to have the same ssh problem though. The error message kinda threw me off. But with -v it indeed shows that ssh fails because it cannot open a pty.
Hmm... maybe we are on to something... Can you do a ls or tree of your /dev dir in the jail?

Here is mine (default ezjail jail):

Code:
@jail# tree /dev
/dev
|-- fd
|   |-- 0
|   |-- 1
|   `-- 2
|-- log -> ../var/run/log
|-- null
|-- ptmx
|-- pts
|-- random
|-- stderr -> fd/2
|-- stdin -> fd/0
|-- stdout -> fd/1
|-- urandom -> random
`-- zero
(notice the lack of /dev/tty or /dev/pts/*)
Reply With Quote
  #10  
Old December 8th, 2010, 17:30
SirDice's Avatar
SirDice SirDice is offline
Moderator
 
Join Date: Nov 2008
Location: Rotterdam, Netherlands
Posts: 13,702
Thanks: 47
Thanked 2,022 Times in 1,861 Posts
Default

Mine's the same.
__________________
Senior UNIX Engineer at Unix Support Nederland
Experience is something you don't get until just after you need it.
Reply With Quote
  #11  
Old December 8th, 2010, 19:08
hopla hopla is offline
Junior Member
 
Join Date: Nov 2008
Posts: 34
Thanks: 11
Thanked 3 Times in 2 Posts
Default

Quote:
Originally Posted by SirDice View Post
Mine's the same.
So do you have any theory then why screen is working for you and not for me?
Reply With Quote
  #12  
Old December 9th, 2010, 11:46
hopla hopla is offline
Junior Member
 
Join Date: Nov 2008
Posts: 34
Thanks: 11
Thanked 3 Times in 2 Posts
Default

SirDice, you either have screen compiled with some options I don't know about or you have a very special jail setup or some custom kernel options (I'm running GENERIC) or you are doing something different from what I'm doing.

Because I just can't get screen to work after jexec'ing into jail. Can you please verify for us one more time that the following is absolutely 100% sure working for you? (I especially have a hard time believing this, since you stated that you DO have the same problem with SSH)

Code:
root@host# jexec <jid> sh
root@jail# screen

Screen version 4.00.03 (FAU) 23-Oct-06

<SNIP>

[Press Space or Return to end.]
Because I keep getting (except when I run tmux in the jail before screen):

Code:
root@host# jexec <jid> sh
root@jail# screen
Cannot access '/dev/pts/1': No such file or directory
(where the number 1 changes from time to time of course)
Reply With Quote
  #13  
Old March 26th, 2012, 08:28
tbyte's Avatar
tbyte tbyte is offline
Member
 
Join Date: Nov 2008
Location: Sofia, Bulgaria, EU
Posts: 105
Thanks: 3
Thanked 2 Times in 2 Posts
Default

Quote:
Originally Posted by hopla View Post
Code:
root@host# jexec <jid> sh
root@jail# screen
Cannot access '/dev/pts/1': No such file or directory
(where the number 1 changes from time to time of course)
Same here ... It tries to open the same tty you have logged in on outside of the jail which is not accessible (of course) inside.

Last edited by DutchDaemon; March 26th, 2012 at 11:28.
Reply With Quote
Reply

Tags
jexec, ssh, tty

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to bypass lost access to ssh? Mad_Dud Web & Network Services 2 November 14th, 2010 13:38
Is this secure enough for sharing SSH/SFTP access? olav Web & Network Services 8 August 24th, 2010 18:36
How to restrict access to SSH with pam_group.so malexe Web & Network Services 2 March 6th, 2010 01:12
ssh access cwhitmore Firewalls 2 April 20th, 2009 04:06
SSH: Limit root access to a certain port dordal General 4 March 18th, 2009 16:24


All times are GMT +1. The time now is 20:15.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
The mark FreeBSD is a registered trademark of The FreeBSD Foundation and is used by The FreeBSD Project with the permission of The FreeBSD Foundation.
Web protection and acceleration provided by CloudFlare
0