how to get TTY with SSH session

how to get TTY with SSH session

am 14.04.2008 01:57:06 von inetquestion

When you enter the following command:

ssh "set > test.txt; cat test.txt"

The results show that no TTY was assigned to the session. Is there a
way to force a TTY to be assigned when invoking commands over ssh and
not remaining on the remote system? for example could I have
entered some command to begin with on the remote when which would have
caused me to get a TTY such as...:

ssh "; set > test.txt; cat test.txt"

Re: how to get TTY with SSH session

am 14.04.2008 03:50:22 von Barry Margolin

In article
,
inetquestion wrote:

> When you enter the following command:
>
> ssh "set > test.txt; cat test.txt"
>
> The results show that no TTY was assigned to the session.

How does that command show that no tty was assigned? set displays all
the shell variables that are set.

> Is there a
> way to force a TTY to be assigned when invoking commands over ssh and
> not remaining on the remote system? for example could I have
> entered some command to begin with on the remote when which would have
> caused me to get a TTY such as...:
>
> ssh "; set > test.txt; cat test.txt"

Use the -t option to ssh to force a pseudo-tty to be used.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE don't copy me on replies, I'll read them in the group ***

Re: how to get TTY with SSH session

am 14.04.2008 14:10:12 von gazelle

In article ,
Barry Margolin wrote:
>In article
>,
> inetquestion wrote:
>
>> When you enter the following command:
>>
>> ssh "set > test.txt; cat test.txt"
>>
>> The results show that no TTY was assigned to the session.
>
>How does that command show that no tty was assigned? set displays all
>the shell variables that are set.

Yes. But the point is that you can then visually scan the output for
the variable(s) in which you are interested. Not very elegant, but a
reasonable first shot for a beginner.

When I tested this, I was using: set | grep -i tty

>> Is there a
>> way to force a TTY to be assigned when invoking commands over ssh and
>> not remaining on the remote system? for example could I have
>> entered some command to begin with on the remote when which would have
>> caused me to get a TTY such as...:
>>
>> ssh "; set > test.txt; cat test.txt"
>
>Use the -t option to ssh to force a pseudo-tty to be used.

Yes. Just like it says in "man ssh"...

Now, the next question is "Why?". Why does the OP want this?

Re: how to get TTY with SSH session

am 14.04.2008 14:45:50 von inetquestion

The root of this problem is SSH tunnel from server A -> B works when
the user gets a shell on server B. However when SSH is forked in the
background, the tunnel doesn't work. Using the -t option doesn't have
any effect in this particular case... This only happens when server
B is running SunSSH on solaris 10. Unfortunately i don't have the
option to change that

Re: how to get TTY with SSH session

am 15.04.2008 03:43:31 von Barry Margolin

In article ,
gazelle@xmission.xmission.com (Kenny McCormack) wrote:

> In article ,
> Barry Margolin wrote:
> >In article
> >,
> > inetquestion wrote:
> >
> >> When you enter the following command:
> >>
> >> ssh "set > test.txt; cat test.txt"
> >>
> >> The results show that no TTY was assigned to the session.
> >
> >How does that command show that no tty was assigned? set displays all
> >the shell variables that are set.
>
> Yes. But the point is that you can then visually scan the output for
> the variable(s) in which you are interested. Not very elegant, but a
> reasonable first shot for a beginner.

And what variables would that be? BTW, what was the point of writing it
to a file and then catting the file? Another "reasonable first shot"?

>
> When I tested this, I was using: set | grep -i tty

When I do that, all I see is:

imac:barmar $ set | grep -i tty
HOSTTYPE=i386

which has nothing to do with TTY assignment. AFAIK, there are no
standard shell variables that indicate whether you have a TTY assigned.
Why not just use the tty(1) command?

ssh "tty"

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE don't copy me on replies, I'll read them in the group ***

Re: how to get TTY with SSH session

am 15.04.2008 03:48:26 von Barry Margolin

In article
,
inetquestion wrote:

> The root of this problem is SSH tunnel from server A -> B works when
> the user gets a shell on server B. However when SSH is forked in the
> background, the tunnel doesn't work. Using the -t option doesn't have
> any effect in this particular case... This only happens when server
> B is running SunSSH on solaris 10. Unfortunately i don't have the
> option to change that

It sounds like the problem is that the tunnels are being closed when the
remote command completes, and has nothing to do with whether a tty is
assigned. It works when you get an interactive shell because you keep
that running the entire time.

Try using the -M option.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***

Re: how to get TTY with SSH session

am 15.04.2008 09:59:04 von Mevlut

Barry Margolin wrote:

> And what variables would that be? BTW, what was the point of writing it
> to a file and then catting the file? Another "reasonable first shot"?

The variable is called "SSH_TTY".

$ ssh remotehost "set | grep -i tty"
BASH_EXECUTION_STRING='set | grep -i tty'
HOSTTYPE=i686
$ ssh -t remotehost "set | grep -i tty"
BASH_EXECUTION_STRING='set | grep -i tty'
HOSTTYPE=i686
SSH_TTY=/dev/pts/6
Connection to remotehost closed.

Re: how to get TTY with SSH session

am 15.04.2008 12:59:56 von gazelle

In article ,
DaveB wrote:
>Barry Margolin wrote:
>
>> And what variables would that be? BTW, what was the point of writing it
>> to a file and then catting the file? Another "reasonable first shot"?
>
>The variable is called "SSH_TTY".
>
>$ ssh remotehost "set | grep -i tty"
>BASH_EXECUTION_STRING='set | grep -i tty'
>HOSTTYPE=i686
>$ ssh -t remotehost "set | grep -i tty"
>BASH_EXECUTION_STRING='set | grep -i tty'
>HOSTTYPE=i686
>SSH_TTY=/dev/pts/6
>Connection to remotehost closed.

Actually, I think you have to use "env" rather than "set", in order to
pick up the SSH_* variables.

Re: how to get TTY with SSH session

am 15.04.2008 13:39:10 von Mevlut

On Tuesday 15 April 2008 12:59, Kenny McCormack wrote:

> Actually, I think you have to use "env" rather than "set", in order to
> pick up the SSH_* variables.

My point was to show the existence of the SSH_TTY variable, nothing else.
With env I get the same results:

$ ssh 10.1.1.66 "env | grep -i tty"
$ ssh -t 10.1.1.66 "env | grep -i tty"
SSH_TTY=/dev/pts/6
Connection to 10.1.1.66 closed.

And, wrt the SSH_* variables, the results are consistent both with set and
with env:

$ ssh 10.1.1.66 "env | grep SSH"
SSH_CLIENT=::ffff:10.1.1.1 36186 22
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
SSH_CONNECTION=::ffff:10.1.1.1 36186 ::ffff:10.1.1.66 22

$ ssh -t 10.1.1.66 "env | grep SSH"
SSH_CLIENT=::ffff:10.1.1.1 36187 2
SSH_TTY=/dev/pts/6
SSH_CONNECTION=::ffff:10.1.1.1 36187 ::ffff:10.1.1.66 22
Connection to 10.1.1.66 closed.

$ ssh 10.1.1.66 "set | grep SSH"
BASH_EXECUTION_STRING='set | grep SSH'
SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass
SSH_CLIENT='::ffff:10.1.1.1 36188 22'
SSH_CONNECTION='::ffff:10.1.1.1 36188 ::ffff:10.1.1.66 22'

$ ssh -t 10.1.1.66 "set | grep SSH"
BASH_EXECUTION_STRING='set | grep SSH'
SSH_CLIENT='::ffff:10.1.1.1 36189 22'
SSH_CONNECTION='::ffff:10.1.1.1 36189 ::ffff:10.1.1.66 22'
SSH_TTY=/dev/pts/6
Connection to 10.1.1.66 closed.

--
D.

Re: how to get TTY with SSH session

am 15.04.2008 13:53:09 von gazelle

In article ,
Barry Margolin wrote:
>In article ,
> gazelle@xmission.xmission.com (Kenny McCormack) wrote:
>
>> In article ,
>> Barry Margolin wrote:
>> >In article
>> >,
>> > inetquestion wrote:
>> >
>> >> When you enter the following command:
>> >>
>> >> ssh "set > test.txt; cat test.txt"
>> >>
>> >> The results show that no TTY was assigned to the session.
>> >
>> >How does that command show that no tty was assigned? set displays all
>> >the shell variables that are set.
>>
>> Yes. But the point is that you can then visually scan the output for
>> the variable(s) in which you are interested. Not very elegant, but a
>> reasonable first shot for a beginner.
>
>And what variables would that be?

Whatever works...

>BTW, what was the point of writing it to a file and then catting the
>file? Another "reasonable first shot"?

Yes. Obviously, worrying about UUOC-type things isn't the point of this
thread (although UUOC seems to creep into just about every thread, one
way or the other).

>>
>> When I tested this, I was using: set | grep -i tty
>
>When I do that, all I see is:
>
>imac:barmar $ set | grep -i tty
>HOSTTYPE=i386
>
>which has nothing to do with TTY assignment. AFAIK, there are no
>standard shell variables that indicate whether you have a TTY assigned.

Whatever works. It depends in part on what is your login shell on the
remote system; this determines which shell variables are present/set.
And, if it is (t)csh, you probably have to use "env" instead of "set".

>Why not just use the tty(1) command?
>
>ssh "tty"

Yeah, that should work, too.

Even without the quotes (UUOQ?)

Re: how to get TTY with SSH session

am 15.04.2008 14:53:53 von inetquestion

The problem seems to be a difference between OpenSSH and SunSSH
related to how they interpret "allow tcp forwarding". Sun's version
appears to be more strict as to what it won't allow.