0

I've recently set up a fairly minimal Debian server (fail2ban and ufw installed with the OpenSSH profile enabled) with a user with default shell /bin/bash:

$ grep "$(whoami)" /etc/passwd
nightfirecat:x:1000:1000::/home/nightfirecat:/bin/bash

When I run scp file server.ip from my machine, I get the following output:

$ scp file server.ip
lost connection

However, when I change my default shell on the server to /bin/sh via sudo usermod --shell /bin/sh nightfirecat or sudo chsh -s /bin/sh nightfirecat, the scp command succeeds.

$ scp file server.ip
file                                               100%   16KB 314.8KB/s   00:00

The same behavior is observed when running ssh commands: (using ssh to connect remotely works fine with either shell)

$ ssh server.ip 'echo foo' # /bin/bash shell

$ ssh server.ip 'echo foo' # /bin/sh shell foo

My /var/log/auth.log logs don't seem to indicate any authentication issue, and debug logs from scp don't illuminate the problem. I do have a .bashrc file that runs on login, however its first commands are [ -z "$PS1" ] && exit to exit on non-interactive logins.

1 Answers1

1

The problem was in fact with my .bashrc file. The start of the file previously read as follows:

# If not running interactively, don't do anything
[ -z "$PS1" ] && exit

The problem was exit was quitting out of the shell. Using return instead works as intended:

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

P.S. Credit to https://superuser.com/a/1184787/460089 for this solution.