Foreword: I believe I did my homework. I tried checking the ownership/modes of the relevant files, but I'm still getting the error.
I'm trying to start an SFTP server on GNU/Linux. I made a new user called sftp_server
, created /home/sftp_server/.ssh
, and filled /home/sftp_server/.ssh/sshd_config
with:
AuthorizedKeysFile /home/sftp_server/.ssh/authorized_keys
HostKey /home/sftp_server/.ssh/server_key
Subsystem sftp internal-sftp
PubkeyAuthentication yes
PasswordAuthentication no
ChallengeResponseAuthentication no
Port 2222
AddressFamily any
ListenAddress 0.0.0.0
ListenAddress ::
Then I added the client's public key to /home/sftp_server/.ssh/authorized_keys
.
I ran server as sftp_server
:
sftp_server@system ~> /usr/bin/sshd -f /home/sftp_server/.ssh/sshd_config -D -d
and it launches successfully with
debug1: sshd version OpenSSH_8.4, OpenSSL 1.1.1i 8 Dec 2020
…
Server listening on 0.0.0.0 port 2222.
But my attempt to connect to this server from the client with
user@DESKTOP:~$ sftp -P 2222 192.168.0.102
fails (on the server side) with:
…
Authentication refused: bad ownership or modes for file /home/sftp_server/.ssh/authorized_keys
debug1: restore_uid: (unprivileged)
Failed publickey for user from 192.168.0.103 port 64450 ssh2: ED25519 SHA256:...
Connection closed by authenticating user user 192.168.0.103 port 64450 [preauth]
…
UPDATE: Logging in as sftp_server
doesn't help either.
user@DESKTOP:~$ sftp -P 2222 sftp_server@192.168.0.102
fails on the server side with the same error message.
This is a server-side message, so I'm assuming the server is failing to access the authorized_keys
file properly.
The existing questions
- Why am I still getting a password prompt with ssh with public key authentication?
- Authentication refused: bad ownership or modes for file /var/git/.ssh/authorized_keys
both advises that I should set ownership/modes properly, like:
$ sudo chmod 0700 /home/sftp_server/.ssh
$ sudo chmod 0600 /home/sftp_server/.ssh/authorized_keys
But I've already applied these.
[root@system user]# ls -al /home
…
drwxr-xr-x 7 sftp_server root 4096 Mar 24 15:07 sftp_server
…
[root@system user]# ls -al /home/sftp_server
drwxr-xr-x 7 sftp_server root 4096 Mar 24 15:07 .
drwxr-xr-x 6 root root 4096 Nov 17 2018 ..
…
drwx------ 2 sftp_server sftp_users 4096 Mar 24 14:53 .ssh
…
[root@system user]# ls -al /home/sftp_server/.ssh
…
drwx------ 2 sftp_server sftp_users 4096 Mar 24 14:53 .
drwxr-xr-x 7 sftp_server root 4096 Mar 24 15:07 ..
-rw------- 1 sftp_server sftp_users 162 Mar 24 14:15 authorized_keys
-rw-r--r-- 1 sftp_server sftp_users 410 Mar 24 14:53 sshd_config
…
I'm thinking that
drwxr-xr-x
(755) for/home/sftp_server
drwx------
(700) for/home/sftp_server/.ssh
-rw-------
(600) for/home/sftp_server/.ssh/authorized_keys
are the correct modes, and they all correctly have sftp_server
set as the file owner.
This leaves me puzzled and frustrated for the bad ownership or modes for file
error message.
I'd appreciate any help or hint. Thanks!
authorized_keys
? – Jiri B Mar 24 '21 at 08:55sftp_server
results in the same error. – Minoru Mar 24 '21 at 12:16..
refer to? At least in myls
snippet, all..
directories already have thedrwxr-xr-x
modes, I think? – Minoru Mar 24 '21 at 12:25..
means, I asked what directory you referred to. What file/directory do you suggest to change?/home
or/home/sftp_server
or/home/sftp_server/.ssh
? Which property of that file/directory? By the way, I tried changing the group of/home/sftp_server
but it had no effect. I also doubt it's the group, because the error says "bad ownership or modes." – Minoru Mar 24 '21 at 12:50ls -l /home/sftp_server/.ssh/server_key
? – ilkkachu Mar 24 '21 at 13:02server_key
? Anyway, the setup you want works fine, I just tested it. BTW,debug1: restore_uid: (unprivileged)
shows you are running this SSH daemon as ordinary user -sftp_server
. What distro do you use? – Jiri B Mar 24 '21 at 13:09server_key
. But AFAIK, it should test that one too, so it occurred to me you might want to check that too. – ilkkachu Mar 24 '21 at 13:13man sshd_config
). – Jiri B Mar 24 '21 at 13:18ls -ld / /home
to your question, please (permissions for/
and/home
themselves). I suspect it may be a permissions/ownership issue up the chain of directories from~/.ssh/authorized_keys
– Chris Davies Mar 24 '21 at 13:46002
umask.) Based on the code, the settings here look ok to me... – ilkkachu Mar 24 '21 at 13:49