Mailing List Archive

Fwd: Permissions in chroot SFTP
Hi,
I configured openssh 5.1p1 for sftp server.

Here the specifications in sshd_config file:

Subsystem sftp internal-sftp
Match Group sftp
ForceCommand internal-sftp
ChrootDirectory /home/%u
AllowTcpForwarding no

When a user is logged in, he can't upload his document and he receives
this message:

carlo@Music:~$ sftp user@213.217.147.123
Connecting to 213.217.147.123...
user@213.217.147.123's password:
sftp> put prova
Uploading prova to /prova
Couldn't get handle: Permission denied
sftp>

Here the directory permissions:

[root@sftp-server ~]# ls -la /home/user/
total 24
drwxr-xr-x 6 root sftp 4096 Nov 10 18:05 .
drwxr-xr-x 54 root root 4096 Nov 10 16:48 ..

OK, my user is a sftp group member, and the sftp group hasn't
sufficient permissions to write in user's home directory.

I add the write permission for the sftp group:

[root@sftp-server ~]# chmod 770 /home/user/
[root@sftp-server ~]# ls -la /home/user/
total 24
drwxrwx--- 6 root sftp 4096 Nov 10 18:05 .
drwxr-xr-x 54 root root 4096 Nov 10 16:48 ..


But now the user can't access:

carlo@Music:~$ sftp user@213.217.145.321
Connecting to 213.217.147.123...
user@213.217.145.321's password:
Read from remote host 213.217.145.321: Connection reset by peer
Couldn't read packet: Connection reset by peer

Here the error message in /var/log/messages of sftp-server:

Nov 11 11:33:02 sftp-server sshd[10254]: Accepted password for user
from 213.217.145.329 port 38685 ssh2
Nov 11 11:33:02 sftp-server sshd[10256]: fatal: bad ownership or modes
for chroot directory "/home/user"

I get the same result if I change the ownership of user directory:

[root@sftp-server ~]# chown user.sftp /home/user/
[root@sftp-server ~]# ls -la /home/user/
total 24
drwxrwx--- 6 user sftp 4096 Nov 10 18:05 .
drwxr-xr-x 54 root root 4096 Nov 10 16:48 ..

carlo@Music:~$ sftp user@213.217.145.321
Connecting to 213.217.147.123...
user@213.217.145.321's password:
Read from remote host 213.217.145.321: Connection reset by peer
Couldn't read packet: Connection reset by peer

Nov 11 11:38:11 sftp-server sshd[10267]: Accepted password for user
from 213.217.145.329 port 39285 ssh2
Nov 11 11:38:11 sftp-server sshd[10269]: fatal: bad ownership or modes
for chroot directory "/home/user"

I get the same result if I change the ownership of user directory this way:

[root@sftp-server ~]# chown user.root /home/user/

What can I do in order to grant user access and allow write
permissions in his home directory?

Thanks


--
Carlo Pradissitto

Servizi e Supporto IT

I-WAY S.r.l.
Piazza Caduti di via Fani, 2
03100 Frosinone

Mobile: +393939318571

Tel/Fax: 07751880765

E-mail: c.pradissitto@i-way.it



--
Carlo Pradissitto

Servizi e Supporto IT

I-WAY S.r.l.
Piazza Caduti di via Fani, 2
03100 Frosinone

Mobile: +393939318571

Tel/Fax: 07751880765

E-mail: c.pradissitto@i-way.it
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Fwd: Permissions in chroot SFTP [ In reply to ]
Carlo Pradissitto wrote:
> I get the same result if I change the ownership of user directory
> this way:
>
> [root@sftp-server ~]# chown user.root /home/user/
>
> What can I do in order to grant user access and allow write
> permissions in his home directory?

Start with 755 user:sftp (or 700) and then try user:root.


//Peter
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Fwd: Permissions in chroot SFTP [ In reply to ]
Case 1
[root@sftp-server ~]# cd /home/
[root@sftp-server home]# chown user.sftp user/
[root@sftp-server home]# chmod 755 user/

carlo@Music:~$ sftp user@213.217.147.123
Connecting to 213.217.147.123...
user@213.217.147.123's password:
Read from remote host 213.217.147.123: Connection reset by peer
Couldn't read packet: Connection reset by peer


Case 2
[root@sftp-server home]# chown user.root user/

carlo@Music:~$ sftp user@213.217.147.123
Connecting to 213.217.147.123...
user@213.217.147.123's password:
Read from remote host 213.217.147.123: Connection reset by peer
Couldn't read packet: Connection reset by peer


Case 3
[root@sftp-server home]# chown root.sftp user/

carlo@Music:~$ sftp user@213.217.147.123
Connecting to 213.217.147.123...
user@213.217.147.123's password:
Uploading prova to /prova
Couldn't get handle: Permission denied


2008/11/11 Peter Stuge <peter@stuge.se>:
> Carlo Pradissitto wrote:
>> I get the same result if I change the ownership of user directory
>> this way:
>>
>> [root@sftp-server ~]# chown user.root /home/user/
>>
>> What can I do in order to grant user access and allow write
>> permissions in his home directory?
>
> Start with 755 user:sftp (or 700) and then try user:root.
>
>
> //Peter
> _______________________________________________
> openssh-unix-dev mailing list
> openssh-unix-dev@mindrot.org
> https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
>



--
Carlo Pradissitto

Servizi e Supporto IT

I-WAY S.r.l.
Piazza Caduti di via Fani, 2
03100 Frosinone

Mobile: +393939318571

Tel/Fax: 07751880765

E-mail: c.pradissitto@i-way.it
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Fwd: Permissions in chroot SFTP [ In reply to ]
Carlo Pradissitto wrote:
> Case 1
> [root@sftp-server home]# chown user.sftp user/
> [root@sftp-server home]# chmod 755 user/
>
> carlo@Music:~$ sftp user@213.217.147.123
> Connecting to 213.217.147.123...
> user@213.217.147.123's password:
> Read from remote host 213.217.147.123: Connection reset by peer
> Couldn't read packet: Connection reset by peer
>
>
> Case 2
> [root@sftp-server home]# chown user.root user/
>
> carlo@Music:~$ sftp user@213.217.147.123
> Connecting to 213.217.147.123...
> user@213.217.147.123's password:
> Read from remote host 213.217.147.123: Connection reset by peer
> Couldn't read packet: Connection reset by peer

Ok. I suggest running sshd -ddd on the server side to get clear
messages about which directories need which permissions.


//Peter
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Fwd: Permissions in chroot SFTP [ In reply to ]
Do you read the answer? I don't...

[root@sftp-server ~]# chmod 770 /col-ftp/utenti/prch.ftp

carlo@Music:~$ sftp prch@213.217.147.123
Connecting to 213.217.147.123...
prch@213.217.147.123's password:
Read from remote host 213.217.147.123: Connection reset by peer
Couldn't read packet: Connection reset by peer


debug3: fd 5 is not O_NONBLOCK
debug1: Server will not fork when running in debugging mode.
debug3: send_rexec_state: entering fd = 8 config len 345
debug3: ssh_msg_send: type 0
debug3: send_rexec_state: done
debug1: rexec start in 5 out 5 newsock 5 pipe -1 sock 8
debug1: inetd sockets after dupping: 3, 3
Connection from 213.217.147.119 port 47264
debug1: Client protocol version 2.0; client software version
OpenSSH_4.3p2 Debian-8ubuntu1.5
debug1: match: OpenSSH_4.3p2 Debian-8ubuntu1.5 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.1
debug2: fd 3 setting O_NONBLOCK
debug3: privsep user:group 74:74
debug1: permanently_set_uid: 74/74
debug1: list_hostkey_types: ssh-rsa,ssh-dss
debug1: SSH2_MSG_KEXINIT sent
debug2: Network child is on pid 12665
debug3: preauth child monitor started
debug3: mm_request_receive entering
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit:
diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit:
aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit:
aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit:
hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit:
hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: kex_parse_kexinit:
diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit:
aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit:
aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit:
hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit:
hmac-md5,hmac-sha1,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: mac_setup: found hmac-md5
debug1: kex: client->server aes128-cbc hmac-md5 none
debug2: mac_setup: found hmac-md5
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST received
debug3: mm_request_send entering: type 0
debug3: mm_choose_dh: waiting for MONITOR_ANS_MODULI
debug3: mm_request_receive_expect entering: type 1
debug3: mm_request_receive entering
debug3: monitor_read: checking request 0
debug3: mm_answer_moduli: got parameters: 1024 1024 8192
debug3: mm_request_send entering: type 1
debug2: monitor_read: 0 used once, disabling now
debug3: mm_request_receive entering
debug3: mm_choose_dh: remaining 0
debug1: SSH2_MSG_KEX_DH_GEX_GROUP sent
debug2: dh_gen_key: priv key bits set: 137/256
debug2: bits set: 501/1024
debug1: expecting SSH2_MSG_KEX_DH_GEX_INIT
debug2: bits set: 525/1024
debug3: mm_key_sign entering
debug3: mm_request_send entering: type 4
debug3: mm_key_sign: waiting for MONITOR_ANS_SIGN
debug3: mm_request_receive_expect entering: type 5
debug3: mm_request_receive entering
debug3: monitor_read: checking request 4
debug3: mm_answer_sign
debug3: mm_answer_sign: signature 0x1006f4f0(271)
debug3: mm_request_send entering: type 5
debug2: monitor_read: 4 used once, disabling now
debug3: mm_request_receive entering
debug1: SSH2_MSG_KEX_DH_GEX_REPLY sent
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: KEX done
debug1: userauth-request for user prch service ssh-connection method none
debug1: attempt 0 failures 0
debug3: mm_getpwnamallow entering
debug3: mm_request_send entering: type 6
debug3: mm_getpwnamallow: waiting for MONITOR_ANS_PWNAM
debug3: mm_request_receive_expect entering: type 7
debug3: mm_request_receive entering
debug3: monitor_read: checking request 6
debug3: mm_answer_pwnamallow
debug3: Trying to reverse map address 213.217.147.119.
debug2: parse_server_config: config reprocess config len 345
debug3: checking match for 'Group sftp' user prch host 213.217.147.119
addr 213.217.147.119
debug1: user prch matched group list sftp at line 116
debug3: match found
debug3: reprocess config:117 setting ForceCommand internal-sftp
debug3: reprocess config:118 setting ChrootDirectory /col-ftp/utenti/%u.ftp
debug3: reprocess config:119 setting AllowTcpForwarding no
debug3: auth_shadow_acctexpired: today 14195 sp_expire -1 days left -14196
debug3: account expiration disabled
debug3: mm_answer_pwnamallow: sending MONITOR_ANS_PWNAM: 1
debug3: mm_request_send entering: type 7
debug2: monitor_read: 6 used once, disabling now
debug3: mm_request_receive entering
debug2: input_userauth_request: setting up authctxt for prch
debug3: mm_inform_authserv entering
debug3: mm_request_send entering: type 3
debug2: input_userauth_request: try method none
debug3: mm_auth_password entering
debug3: mm_request_send entering: type 10
debug3: mm_auth_password: waiting for MONITOR_ANS_AUTHPASSWORD
debug3: mm_request_receive_expect entering: type 11
debug3: mm_request_receive entering
debug3: monitor_read: checking request 3
debug3: mm_answer_authserv: service=ssh-connection, style=
debug2: monitor_read: 3 used once, disabling now
debug3: mm_request_receive entering
debug3: monitor_read: checking request 10
debug3: mm_answer_authpassword: sending result 0
debug3: mm_request_send entering: type 11
Failed none for prch from 213.217.147.119 port 47264 ssh2
debug3: mm_request_receive entering
debug3: mm_auth_password: user not authenticated
debug1: userauth-request for user prch service ssh-connection method
keyboard-interactive
debug1: attempt 1 failures 0
debug2: input_userauth_request: try method keyboard-interactive
debug1: keyboard-interactive devs
debug1: auth2_challenge: user=prch devs=
debug1: kbdint_alloc: devices ''
debug2: auth2_challenge_start: devices
debug1: userauth-request for user prch service ssh-connection method password
debug1: attempt 2 failures 1
debug2: input_userauth_request: try method password
debug3: mm_auth_password entering
debug3: mm_request_send entering: type 10
debug3: mm_auth_password: waiting for MONITOR_ANS_AUTHPASSWORD
debug3: mm_request_receive_expect entering: type 11
debug3: mm_request_receive entering
debug3: monitor_read: checking request 10
debug3: auth_shadow_pwexpired: today 14195 sp_lstchg 14193 sp_max 99999
debug3: mm_answer_authpassword: sending result 1
debug3: mm_request_send entering: type 11
Accepted password for prch from 213.217.147.119 port 47264 ssh2
debug1: monitor_child_preauth: prch has been authenticated by privileged process
debug3: mm_get_keystate: Waiting for new keys
debug3: mm_request_receive_expect entering: type 24
debug3: mm_request_receive entering
debug3: mm_auth_password: user authenticated
debug3: mm_send_keystate: Sending new keys: 0x1006f8c0 0x1006f7f8
debug3: mm_newkeys_to_blob: converting 0x1006f8c0
debug3: mm_newkeys_to_blob: converting 0x1006f7f8
debug3: mm_send_keystate: New keys have been sent
debug3: mm_send_keystate: Sending compression state
debug3: mm_request_send entering: type 24
debug3: mm_send_keystate: Finished sending state
debug3: mm_newkeys_from_blob: 0x100769b0(118)
debug2: mac_setup: found hmac-md5
debug3: mm_get_keystate: Waiting for second key
debug3: mm_newkeys_from_blob: 0x100769b0(118)
debug2: mac_setup: found hmac-md5
debug3: mm_get_keystate: Getting compression state
debug3: mm_get_keystate: Getting Network I/O buffers
debug3: mm_share_sync: Share sync
debug3: mm_share_sync: Share sync end
User child is on pid 12666
debug3: mm_request_receive entering
debug3: safely_chroot: checking '/'
debug3: safely_chroot: checking '/col-ftp/'
debug3: safely_chroot: checking '/col-ftp/utenti/'
debug3: safely_chroot: checking '/col-ftp/utenti/prch.ftp'
bad ownership or modes for chroot directory "/col-ftp/utenti/prch.ftp"
debug1: do_cleanup
debug1: do_cleanup

2008/11/11 Peter Stuge <peter@stuge.se>:
> Carlo Pradissitto wrote:
>> Case 1
>> [root@sftp-server home]# chown user.sftp user/
>> [root@sftp-server home]# chmod 755 user/
>>
>> carlo@Music:~$ sftp user@213.217.147.123
>> Connecting to 213.217.147.123...
>> user@213.217.147.123's password:
>> Read from remote host 213.217.147.123: Connection reset by peer
>> Couldn't read packet: Connection reset by peer
>>
>>
>> Case 2
>> [root@sftp-server home]# chown user.root user/
>>
>> carlo@Music:~$ sftp user@213.217.147.123
>> Connecting to 213.217.147.123...
>> user@213.217.147.123's password:
>> Read from remote host 213.217.147.123: Connection reset by peer
>> Couldn't read packet: Connection reset by peer
>
> Ok. I suggest running sshd -ddd on the server side to get clear
> messages about which directories need which permissions.
>
>
> //Peter
> _______________________________________________
> openssh-unix-dev mailing list
> openssh-unix-dev@mindrot.org
> https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
>



--
Carlo Pradissitto

Servizi e Supporto IT

I-WAY S.r.l.
Piazza Caduti di via Fani, 2
03100 Frosinone

Mobile: +393939318571

Tel/Fax: 07751880765

E-mail: c.pradissitto@i-way.it
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev
Re: Fwd: Permissions in chroot SFTP [ In reply to ]
Circa 2008-11-11 06:39 dixit Carlo Pradissitto:

: I configured openssh 5.1p1 for sftp server.
:
: Here the specifications in sshd_config file:
:
: Subsystem sftp internal-sftp
: Match Group sftp
: ForceCommand internal-sftp
: ChrootDirectory /home/%u
: AllowTcpForwarding no
:
: When a user is logged in, he can't upload his document and he receives
: this message:
:
: carlo@Music:~$ sftp user@213.217.147.123
: Connecting to 213.217.147.123...
: user@213.217.147.123's password:
: sftp> put prova
: Uploading prova to /prova
: Couldn't get handle: Permission denied
: sftp>

[...]

You don't want the user to have write permissions to the chroot
directory. If you do, the user has the potential to gain root
privileges inside the chroot.

Best is to make the chroot directory owned by root, as sshd is trying to
tell you. Create a user-writable directory under the chroot directory
instead.

--
jim knoble | jmknoble@pobox.com | http://www.pobox.com/~jmknoble/
(GnuPG key ID: C6F31FFA >>>>>> http://www.pobox.com/~jmknoble/keys/ )
(GnuPG fingerprint: 99D8:1D89:8C66:08B5:5C34::5527:A543:8C33:C6F3:1FFA)
+----------------------------------------------------------------------+
|[L]iberty, as we all know, cannot flourish in a country that is perma-|
| nently on a war footing, or even a near-war footing. --Aldous Huxley|
+----------------------------------------------------------------------+
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev