Chroot and sftp with SSH 4.3p rel 83 on Redhat EL5

Latest response

Hi,

we have redhat el5. I ve one user like below

username :x:1198:1198: name surname :/dir1/dir2/dir3/username.domain.edu.tr:bin/false

in sshd_config

Subsystem sftp internal-sftp
Chrott directory %h

when i connect to system with winscp i successfully connect but, i can't write files on user root directory username.domain.edu.tr

because /dir1/dir2/dir3/username.domain.edu.tr folders owned by root:root. otherwise when i changed owner information of username.domain.edu.tr folder to local user

i cannot logon with winscp.

i'm really stuck in here.

what is the correct confiuration of chrooted sftp on ssh ?

thanks in advance ?

Responses

Hello

ChrootDirectory %h

With above, userhome direcotry is owned by root user, so %user cannot write in its own home directory, You need to create a directory in home directory which is owned by%user.

Something like this.

[root@server1 ~]# cat /etc/ssh/sshd_config |egrep -v "^#|^$"
Protocol 2
SyslogFacility AUTHPRIV
PasswordAuthentication yes
ChallengeResponseAuthentication no
GSSAPIAuthentication yes
GSSAPICleanupCredentials yes
UsePAM yes
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL
X11Forwarding yes
ChrootDirectory %h
Subsystem sftp internal-sftp -f AUTHPRIV -l VERBOSE

[root@server1 ~]# ll -d /home/
drwxr-xr-x 3 root root 4096 Jan 3 11:21 /home/
[root@server1 ~]# ll -d /home/atolani/
drwxr-xr-x 6 root root 4096 Jan 3 11:26 /home/atolani/
[root@server1 ~]# ll -d /home/atolani/.ssh/
drwx------ 2 atolani atolani 4096 Jan 3 11:27 /home/atolani/.ssh/
[root@server1 ~]# ll /home/atolani/.ssh/
total 8
-rw------- 1 atolani atolani 401 Jan 3 11:27 authorized_keys
[root@server1 ~]# ll /home/atolani/uploads/
total 16
drwxr-xr-x 2 atolani atolani 4096 Jan 3 11:27 1
drwxr-xr-x 2 atolani atolani 4096 Jan 3 11:24 arpit

With this configuration, You will not be able to write into the home directory but a folder created under the home directory In my case it is home_directory/uploads

$ sftp atolani@192.168.122.240
Connecting to 192.168.122.240...
sftp> ls
dev uploads
sftp> cd uploads
sftp> mkdir 1 2 3
sftp> quit

Cheers..