You are not logged in.

#1 2023-12-22 14:58:28

rmnet
Member
Registered: 2010-04-16
Posts: 12

[SOLVED] ssh server terminates connection immediately after connect

The following happens regardless of whether I try to log in locally or remotely.

Immediately after entering the password, which is accepted, the ssh server closes the connection.

Here is the journal (with LogLevel = DEBUG)

Dez 22 15:42:43 cielo sshd[2264]: debug1: PAM: password authentication accepted for XXXX
Dez 22 15:42:43 cielo sshd[2264]: debug1: do_pam_account: called
Dez 22 15:42:43 cielo sshd[2264]: Accepted password for XXXX from ::1 port 36832 ssh2
Dez 22 15:42:43 cielo sshd[2264]: debug1: monitor_child_preauth: user XXXX authenticated by privileged process
Dez 22 15:42:43 cielo sshd[2264]: debug1: monitor_read_log: child log fd closed
Dez 22 15:42:43 cielo sshd[2264]: debug1: PAM: establishing credentials
Dez 22 15:42:43 cielo sshd[2264]: pam_unix(sshd:session): session opened for user XXXX(uid=1000) by XXXX(uid=0)
Dez 22 15:42:43 cielo systemd-logind[525]: New session 7 of user XXXX.
Dez 22 15:42:43 cielo systemd[1]: Started Session 7 of User XXXX.
Dez 22 15:42:43 cielo sshd[2264]: User child is on pid 2276
Dez 22 15:42:43 cielo sshd[2276]: debug1: PAM: establishing credentials
Dez 22 15:42:43 cielo sshd[2276]: debug1: permanently_set_uid: 1000/1000
Dez 22 15:42:43 cielo sshd[2276]: debug1: rekey in after 134217728 blocks
Dez 22 15:42:43 cielo sshd[2276]: debug1: rekey out after 134217728 blocks
Dez 22 15:42:43 cielo sshd[2276]: debug1: ssh_packet_set_postauth: called
Dez 22 15:42:43 cielo sshd[2276]: debug1: active: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
Dez 22 15:42:43 cielo sshd[2276]: debug1: Entering interactive session for SSH2.
Dez 22 15:42:43 cielo sshd[2276]: debug1: server_init_dispatch
Dez 22 15:42:43 cielo sshd[2276]: debug1: server_input_channel_open: ctype session rchan 0 win 1048576 max 16384
Dez 22 15:42:43 cielo sshd[2276]: debug1: input_session_request
Dez 22 15:42:43 cielo sshd[2276]: debug1: channel 0: new session [server-session] (inactive timeout: 0)
Dez 22 15:42:43 cielo sshd[2276]: debug1: session_new: session 0
Dez 22 15:42:43 cielo sshd[2276]: debug1: session_open: channel 0
Dez 22 15:42:43 cielo sshd[2276]: debug1: session_open: session 0: link with channel 0
Dez 22 15:42:43 cielo sshd[2276]: debug1: server_input_channel_open: confirm session
Dez 22 15:42:43 cielo sshd[2276]: debug1: server_input_global_request: rtype no-more-sessions@openssh.com want_reply 0
Dez 22 15:42:43 cielo sshd[2276]: debug1: server_input_channel_req: channel 0 request pty-req reply 1
Dez 22 15:42:43 cielo sshd[2276]: debug1: session_by_channel: session 0 channel 0
Dez 22 15:42:43 cielo sshd[2276]: debug1: session_input_channel_req: session 0 req pty-req
Dez 22 15:42:43 cielo sshd[2276]: debug1: Allocating pty.
Dez 22 15:42:43 cielo sshd[2264]: debug1: session_new: session 0
Dez 22 15:42:43 cielo sshd[2276]: debug1: session_pty_req: session 0 alloc /dev/pts/0
Dez 22 15:42:43 cielo sshd[2276]: debug1: server_input_channel_req: channel 0 request shell reply 1
Dez 22 15:42:43 cielo sshd[2276]: debug1: session_by_channel: session 0 channel 0
Dez 22 15:42:43 cielo sshd[2276]: debug1: session_input_channel_req: session 0 req shell
Dez 22 15:42:43 cielo sshd[2276]: Starting session: shell on pts/0 for XXXX from ::1 port 36832 id 0
Dez 22 15:42:43 cielo sshd[2281]: debug1: Setting controlling tty using TIOCSCTTY.
Dez 22 15:42:43 cielo sshd[2276]: debug1: Received SIGCHLD.
Dez 22 15:42:43 cielo sshd[2276]: debug1: session_by_pid: pid 2281
Dez 22 15:42:43 cielo sshd[2276]: debug1: session_exit_message: session 0 channel 0 pid 2281 exit 1
Dez 22 15:42:43 cielo sshd[2276]: debug1: session_exit_message: release channel 0
Dez 22 15:42:43 cielo sshd[2264]: debug1: session_by_tty: session 0 tty /dev/pts/0
Dez 22 15:42:43 cielo sshd[2264]: debug1: session_pty_cleanup2: session 0 release /dev/pts/0
Dez 22 15:42:43 cielo sshd[2276]: debug1: session_by_channel: session 0 channel 0
Dez 22 15:42:43 cielo sshd[2276]: debug1: session_close_by_channel: channel 0 child 0
Dez 22 15:42:43 cielo sshd[2276]: Close session: user XXXX from ::1 port 36832 id 0
Dez 22 15:42:43 cielo sshd[2276]: debug1: channel 0: free: server-session, nchannels 1
Dez 22 15:42:43 cielo sshd[2276]: Received disconnect from ::1 port 36832:11: disconnected by user
Dez 22 15:42:43 cielo sshd[2276]: Disconnected from user XXXX ::1 port 36832
Dez 22 15:42:43 cielo sshd[2276]: debug1: do_cleanup
Dez 22 15:42:43 cielo sshd[2264]: debug1: do_cleanup
Dez 22 15:42:43 cielo sshd[2264]: debug1: PAM: cleanup
Dez 22 15:42:43 cielo sshd[2264]: debug1: PAM: closing session
Dez 22 15:42:43 cielo sshd[2264]: pam_unix(sshd:session): session closed for user XXXX
Dez 22 15:42:43 cielo sshd[2264]: debug1: PAM: deleting credentials
Dez 22 15:42:43 cielo systemd[1]: session-7.scope: Deactivated successfully.
Dez 22 15:42:43 cielo systemd-logind[525]: Session 7 logged out. Waiting for processes to exit.
Dez 22 15:42:43 cielo systemd-logind[525]: Removed session 7.

Can anyone help?

Best regards
René

Last edited by rmnet (2023-12-23 05:51:30)

Offline

#2 2023-12-22 21:07:08

seth
Member
Registered: 2012-09-03
Posts: 60,787

Re: [SOLVED] ssh server terminates connection immediately after connect

Please use [code][/code] tags. Edit your post in this regard.

Dez 22 15:42:43 cielo sshd[2264]: Accepted password for XXXX from ::1 port 36832 ssh2
Dez 22 15:42:43 cielo sshd[2276]: Starting session: shell on pts/0 for XXXX from ::1 port 36832 id 0
Dez 22 15:42:43 cielo sshd[2276]: debug1: Received SIGCHLD.
Dez 22 15:42:43 cielo sshd[2276]: Close session: user XXXX from ::1 port 36832 id 0
Dez 22 15:42:43 cielo sshd[2276]: Received disconnect from ::1 port 36832:11: disconnected by user
Dez 22 15:42:43 cielo sshd[2276]: Disconnected from user XXXX ::1 port 36832

This looks more like the child is bailing out, perhaps an issue w/ the users shell?
Do you try to  enforce a shell?
Did you botch /etc/shells?
Can you "ssh <server> /usr/bin/ps"?

Offline

#3 2023-12-22 21:45:32

rmnet
Member
Registered: 2010-04-16
Posts: 12

Re: [SOLVED] ssh server terminates connection immediately after connect

seth wrote:

This looks more like the child is bailing out, perhaps an issue w/ the users shell?

I guess you're right, but I can't see what's wrong.

Do you try to  enforce a shell?

Seams to work:

ssh localhost /bin/bash
XXX@localhost's password: ****
date
Fri Dec 22 22:38:15 CET 2023
exit

Did you botch /etc/shells?

Never touched.

cat /etc/shells
# Pathnames of valid login shells.
# See shells(5) for details.

/bin/sh
/bin/bash
/bin/rbash
/usr/bin/git-shell
/usr/bin/bash
/usr/bin/rbash
/usr/bin/sh

Can you "ssh <server> /usr/bin/ps"?

Yes I can beside others:

ssh localhost /usr/bin/date
XXXX@localhost's password: ****
Fri Dec 22 22:41:59 CET 2022

Last edited by rmnet (2023-12-22 21:48:47)

Offline

#4 2023-12-22 21:54:31

seth
Member
Registered: 2012-09-03
Posts: 60,787

Re: [SOLVED] ssh server terminates connection immediately after connect

Seams to work:

I meant  via a user or key specific server config:
https://man.archlinux.org/man/core/open … IN_PROCESS
https://man.archlinux.org/man/core/open … =_command_

Latter seems irrelevant.
Since you can run random commands, including bash,  is there ~/.ssh/rc or  /etc/ssh/sshrc and what actually is your users default shell (on the server)?

Edit: assumign your login shell is bash, what does you ~/.bash_profile/.bashrc look like?
ssh will default to the login shell, but you're explicitly runnign an interactive shell - the login shell might simply terminate or do other stuff that's not the case for a regular interacive shell.

Last edited by seth (2023-12-22 21:59:54)

Offline

#5 2023-12-22 22:26:42

rmnet
Member
Registered: 2010-04-16
Posts: 12

Re: [SOLVED] ssh server terminates connection immediately after connect

Edit: assumign your login shell is bash, what does you ~/.bash_profile/.bashrc look like?

Yes login shell is bash.

$ echo $SHELL
/bin/bash

$ cat  ~/.bash_profile
[[ -f ~/.bashrc ]] && . ~/.bashrc
if [ -z "${DISPLAY}" ]; then
  exec startx > /dev/null 2>&1
fi

$ cat  ~/.bashrc
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
alias ls='ls --color=auto'
PS1='[\u@\h \W]\$ '
export PATH=$PATH:~/Local/bin:~/.local/share/gem/ruby/3.0.0/bin
export EDITOR=emacs
export GTK_OVERLAY_SCROLLING=0
export SWT_GTK3=0

Last edited by rmnet (2023-12-23 05:44:01)

Offline

#6 2023-12-22 22:44:50

rmnet
Member
Registered: 2010-04-16
Posts: 12

Re: [SOLVED] ssh server terminates connection immediately after connect

Works now!

ssh localhost
XXXX@localhost's password: 
Last login: Fri Dec 22 23:38:26 2023 from ::1

Condition for starting x set correctly in ~/.bash_profile.

#  if [ -z "${DISPLAY}" ]; then
if [ -z "$DISPLAY" ] && [ "$XDG_VTNR" = 1 ]; then
   exec startx > /dev/null 2>&1
fi

Thanks for putting me on the right direction!

Offline

Board footer

Powered by FluxBB