Tuesday 20 November 2018

SFTP connection for single user to single directory

How to restict a user to use another directory?

Step 1

Create a directory with following command

mkdir /sftp-test

mkdir /sftp-test/sftp

then create a user and group 

groupadd usersftp

useradd -g usersftp-d /sftp-test -s /sbin/nologin sftpuser

Step 2

Edit the sshd_config file to allow the user to access perticular directory.

vi /etc/ssh/sshd_config

add the following lines and # the following

 Subsystem      sftp    /usr/libexec/openssh/sftp-server
#Subsystem      sftp    /usr/libexec/openssh/sftp-server

add the following 

Subsystem sftp internal-sftp

Match Group exchange
        ChrootDirectory %h
        ForceCommand internal-sftp
        AllowTcpForwarding no
        X11Forwarding no 


Step 3

Now we need to set the permissionas follows

chown root:root /sftp-test

chown sftpuser:root  /sftp-test/sftp

now restart the sshd and check it will work 100%

service sshd restart



 

Permanent hostname setup for RHEL7

Step 1 Set the host name on NMTUI tool like following nmtui set host name   then save and exit Step 2 add the following l...