Linux Programmer | RHCE | RHCSA

Search This Blog

Thursday, 26 March 2026

Restrict SSH and Allow with SFTP

Create SFTP user: 
```
sudo useradd -M -s /sbin/nologin sftpuser
sudo passwd sftpuser
```
Add below lines into, /etc/ssh/sshd_config
```
Match User sftpuser
    ChrootDirectory /data/sftp
    ForceCommand internal-sftp
    PasswordAuthentication yes
    AllowTcpForwarding no
    X11Forwarding no
    PermitTTY no
```
Create folder and set permissions:
```
sudo chown root:root /data/sftp
sudo chmod 755 /data/sftp

sudo mkdir -p /data/sftp/upload
sudo chown sftpuser:sftpuser /data/sftp/upload
```
So the final structure should be:
```
/data/sftp        → owned by root:root (755)
/data/sftp/upload → owned by sftpuser:sftpuser (755)
```
Restart ssh:
```
/etc/init.d/ssh restart
```

And check by connecting with SFTP. it works.

it will show an error during connecting with SSH. 

1 comment:

  1. make sure to set 755 permissions to parent directory. i.e. /data.
    and ownership should be root.

    ReplyDelete

High Disk IO Investigation

  Priority Investigation Commands High Identify processes generating disk I/O iotop -oPa High Check disk utilization and latency iostat -xz ...