I am trying to create a new user and restrict his access to only a single folder in /usr/local/. So I did some google and followed the following steps.
groupadd controlgroup1
cd /usr/local
mkdir controlfolder1
chmod g+rw controlfolder1/
chgrp -R controlgroup1 controlfolder1/
useradd control1
passwd control1
gpasswd -a control1 controlgroup1
I went into /etc/sshd_config
and toward the end of the file I added this
Match Group controlgroup1
# Force the connection to use SFTP and chroot to the required directory.
ForceCommand internal-sftp
ChrootDirectory /usr/local/controlfolder1/
# Disable tunneling, authentication agent, TCP and X11 forwarding.
PermitTunnel no
AllowAgentForwarding no
AllowTcpForwarding no
X11Forwarding no
I restarted ssh: systemctl restart sshd
.
So when I tried to login the control1 user I saw this in the log file ?
Code:
Accepted password for control1 from 192.168.1.8 port 52912 ssh2
May 5 14:12:47 localhost sshd[2639]: pam_unix(sshd:session): session opened for user control1 by (uid=0)
May 5 14:12:47 localhost sshd[2639]: fatal: bad ownership or modes for chroot directory component "/usr/local/controlfolder1/" [postauth]
May 5 14:12:47 localhost sshd[2639]: pam_unix(sshd:session): session closed for user control1
I have ensure control1 one is the owner of it .
ls -ld controlfolder1/
drwxrwxr-x. 2 control1 controlgroup1 6 May 5 13:58 controlfolder1/
I have followed the step but I have a new issue on the "chown -R control1:controlgroup1 /usr/local/controlfolder1/control1" . So this is different. I also want to give ssh access not just sftp ? I hope this will clear the duplication error.