SSH suddenly closes connection, after changing login shell

Hello, everyone!

A Linux-background person here who got a job with an organization that has a few FreeBSD machines.
I was given SSH access to one of them. It used password authentication. Fast forward a couple of months, and today I added two packages: `pkg install bash` and `pkg install mc-nox11`.
Next, I ran `chsh -s /usr/local/bin/bash` to get the shell that `mc` likes, did some work in `mc`, and ran `chsh -s /sbin/sh`.
Once this was done, I could no longer log in through SSH. It displayed 'Closed connection by <IP address> port 22'.
Having checked everything: that OpenSSH was enabled and up, that the port was still open on the firewall, that password auth was still enabled, etc, I ran `ssh -vvv` and found that it establishes the connection, negotiates the ciphers/keys, and bails out. I switched each of the above items off, rebooted the box, switched them back on, but no dice.
After all, I fixed this by `ssh-copy-id <user>@<IP address>` which placed my cert on the server, and then I could connect again.
Hence the question: what have I done, and can that be reverted?
If this is a difficult question, which requires an investigation, we don't absolutely need to spend the effort, but if this is something simple that everyone (except me, obviously) knows off the top of their heads, then why not revert this system back to the state before I messed with it?

Thank you for your help!
 
Doesn't ring a bell.

If you can you should run a non-background debug printing sshd on the server. It will print the rejection reason.
 
% which sh
/bin/sh

This is rather my typo when reproducing it by memory than a real root cause. The shell continued to work, and olnly the SSH broke.
 
The shell continued to work, and olnly the SSH broke.
/bin/sh is the fallback for local logins (IIRC; at least for root), so it still works. for remote connections if the defined shell does not exist, the connection is dropped (which is the only correct behavior for several reasons).
Set the correct path to sh for your user and remote logins will work again.
 
What version of FreeBSD? mc-nox11 was deleted from port (moved to misc/mc) on 2024-01-15. /bin/sh fallback was introduced recently, perhaps that system is not upgraded and ports too.
 
Do you know what kind of permission issue?
There used to be restrictions on $HOME. Not sure if they still hold, but good housekeeping is $HOME should not be world writable. Mode 755 is usual (drwxr-xr-x).

The permissions applicable to $HOME/.ssh, and its contents, are documented in sshd(8). The most important ones, including the directory $HOME/.ssh itself, are all mode 700 (read/write for only the owner).

Public keys ($HOME/.ssh/*.pub) are generally mode 644 (-rw-r--r--).
 
Problematic in more ways than one. Logging in as root with ssh is extremely poor practice.
'Poor' is a judgemental and subjective term, whereas this forum is technical, which implies impartiality. You ought have understood that I do not come here for judgement but for technical considerations. You will not be responsible for any damage, so let's skip the easy subjective part.
 
'Poor' is a judgemental and subjective term, whereas this forum is technical, which implies impartiality. You ought have understood that I do not come here for judgement but for technical considerations. You will not be responsible for any damage, so let's skip the easy subjective part.
You made four posts on the this subject, seeking assistance, without bothering to divulge a critically significant technical issue, which is that you were doing something that nobody expected you would do. i.e. logging in directly as root. You might like to consider your own judgement...
 
Back
Top