You are not logged in.

#1 2024-01-07 09:46:38

Enrico1989
Member
Registered: 2018-07-05
Posts: 359

[SOLVED] ssh into itself fails

$ ssh enrico@192.168.0.224
/usr/lib/Xorg.wrap: Only console users are allowed to run the X server
xinit: giving up
xinit: unable to connect to X server: Connection refused
xinit: server error
Couldn't get a file descriptor referring to the console.
Connection to 192.168.0.224 closed.

It's not that I usually ssh on myself, but yesterday I was lazy to get up from bed to turn off the laptop on the desk, so I opened JuiceSSH on my phone, clicked on my laptop profile with the intention to run `sudo systemctl suspend`, but I got the error above.

And I see the same error if I just open a terminal and ssh from there.

And I see the same error if, even after a reboot, I log into a console which will not start X and ssh from there.

Recently I've been playing with possibly X-related settings, given I'm experimenting with xmonad on tty2 while still using i3 on tty1, so it's possible I've screwed something up.

Could my .xinit be somehow the culprit?

[[ -f ~/.Xresources ]] && xrdb -merge -I$HOME ~/.Xresources
xinput set-prop 11 "libinput Tapping Enabled" 1

[[ "$XDG_VTNR" -eq 1 ]] && exec i3
if [[ "$XDG_VTNR" -eq 2 ]]; then
  picom &
  $HOME/miscellaneous/setscreens.sh && nitrogen --restore && exec xmonad
fi

Last edited by Enrico1989 (2024-01-07 16:08:29)

Offline

#2 2024-01-07 10:35:48

Enrico1989
Member
Registered: 2018-07-05
Posts: 359

Re: [SOLVED] ssh into itself fails

In hindsight, I also think whatever the problem is, it is affecting not just SSH:

$ showkey 
Couldn't get a file descriptor referring to the console.
$ echo $?
1

This, however, is in X, because from the virtual terminal it works.

 $ showkey
kb mode was UNICODE
[ if you are trying this under X, it might not work
since the X server is also reading /dev/console ]

press any key (program terminates 10s after last keypress)...
keycode 28 release

Last edited by Enrico1989 (2024-01-07 10:41:05)

Offline

#3 2024-01-07 11:46:46

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,047

Re: [SOLVED] ssh into itself fails

Your shells rc or profile tires to autostart xorg what's not gonna happen in an ssh login.
Fix the xorg autostart and condition it on a proper tty.

Edit: this has absolutely nothing to do w/ the showkey behavior in an x11 environment.

Last edited by seth (2024-01-07 11:47:38)

Offline

#4 2024-01-07 14:43:03

Enrico1989
Member
Registered: 2018-07-05
Posts: 359

Re: [SOLVED] ssh into itself fails

Ok, so I have this in my ~/.bash_profile,

[[ -f ~/.bashrc ]] && . ~/.bashrc
[[ ! $DISPLAY && $XDG_VTNR -le 2 ]] && exec startx

which seems in line with §4.2 Autostart X at login.

What's wrong with it?

Yes, I see it does startx, and I do see that connecting via SSH doesn't mean being a console user, and that

/usr/lib/Xorg.wrap: Only console users are allowed to run the X server

but what else can I do, if I want to have X it in 2 vt?

Is the problem the number of the VT? As in, should I startx on consoles, say, 7 and 8 and leave 1 and 2 without X.... because ssh uses 1 (or 2)?

I guess I only need another restriction to startx?

Last edited by Enrico1989 (2024-01-07 14:48:04)

Offline

#5 2024-01-07 14:50:19

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,461
Website

Re: [SOLVED] ssh into itself fails

"seems"?  No, whether something is equal to one is very different from whether it is less-than-or-equal-to two.

Your commentary seems to suggest that you think less-than-or-equal-to 2 is also the same as "1" or "2", but is completely incorrect and is the source of the current problem.  In bash, zero, an infinite number of negative numbers, (nearly) any text string, and an unset variable are all considered less than or equal to 2.

Last edited by Trilby (2024-01-07 14:52:51)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#6 2024-01-07 14:55:35

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,047

Re: [SOLVED] ssh into itself fails

You might also want to check "$(tty)" (though iirc bash also exports that to $TTY) which is gonna look vastly different between a console and an ssh login.

Offline

#7 2024-01-07 15:16:54

Enrico1989
Member
Registered: 2018-07-05
Posts: 359

Re: [SOLVED] ssh into itself fails

Trilby wrote:

you think less-than-or-equal-to 2 is also the same as "1" or "2"

No, but I completely forgot that [[ $nonexistent -eq 0 ]] is true sad

So the problem is solved with

[[ ! $DISPLAY && ( $XDG_VTNR == 1 || $XDG_VTNR == 2 ) ]] && exec startx

One last question before marking as SOLVED. What should

$ echo $?

return on the client right after I've ssh-ed on it? I see 1. Is it normal?!

Last edited by Enrico1989 (2024-01-07 15:21:44)

Offline

#8 2024-01-07 15:21:25

Enrico1989
Member
Registered: 2018-07-05
Posts: 359

Re: [SOLVED] ssh into itself fails

seth wrote:

Edit: this has absolutely nothing to do w/ the showkey behavior in an x11 environment.

Oh, yeah, I see

For showkey to work you need to be in a virtual console

But I remember there's a similar command for the terminal emulator running in a graphical environment, which I used to detect the code of some keys. I'm sure about this. And I kinda remember that the keys I was trying to get the codes for were the media keys. Do you know what program it is, or should I ask another question?

Offline

#9 2024-01-07 15:25:30

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,047

Re: [SOLVED] ssh into itself fails

"echo $?" returns the status of the last command. Always.
The last command of your bash profile/rc is probably the other line in your post.
If you type that into an interactive shell inside an X11 session, what do you guess an immediate "echo $?" will tell you about the success of the command?

Offline

#10 2024-01-07 15:32:32

Enrico1989
Member
Registered: 2018-07-05
Posts: 359

Re: [SOLVED] ssh into itself fails

Ok, then the command that is failing is the following

[[ ! $DISPLAY && ( $XDG_VTNR == 1 || $XDG_VTNR == 2 ) ]] && exec startx

because

[[ ! $DISPLAY && ( $XDG_VTNR == 1 || $XDG_VTNR == 2 ) ]]

returns one, because DISPLAY is set and not zero.

So is this the right solution? (It works, but is wrong for other reasons?

[[ ! $DISPLAY && ( $XDG_VTNR == 1 || $XDG_VTNR == 2 ) ]] && exec startx || true

Offline

#11 2024-01-07 15:52:07

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,047

Re: [SOLVED] ssh into itself fails

Why do you care about it?

ALso

Do you know what program it is, or should I ask another question?

xev

Offline

Board footer

Powered by FluxBB