Subhendu Gogoi
By Subhendu Gogoi

SFTP Configuration in Linux(CENTOS)

SFTP Configuration in Linux(CENTOS)

SFTP Configuration

What is SFTP?

SFTP (Secure File Transfer Protocol) is a file transfer protocol that leverages a set of utilities that provide secure access to a remote computer to deliver secure communications. It leverages SSH (Secure Socket Shell or Secure Shell) and is frequently also referred to as ‘Secure Shell File Transfer Protocol’.

Instructions

To install an SFTP server on a CENTOS Linux Server, follow the below steps:

  1. Execute the following command to check whether SSH is installed
1
2
3
    sudo rpm -qa | grep ssh

  1. If SSH is not installed, run the following command
1
2
3
    sudo yum install openssh-server

  1. Open port 22
1
2
3
    sudo iptables -I INPUT -p tcp --dport 22 -j ACCEPT

  1. Create a user and provide new password for that user
1
2
3
4
5
    sudo useradd {user_name}

    sudo passwd {user_name}

  1. Create a directory for the file transfer and make the changes
1
2
3
4
5
6
7
    sudo mkdir {directory_name}

    sudo chgrp {user_name} {directory_name}

    sudo chown {user_name} {directory_name}

  1. In /etc/ssh/sshd_config file add the below configuration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
    Match User {user_name}

    ForceCommand internal-sftp

    PubkeyAuthentication yes

    PasswordAuthentication yes

    ChrootDirectory {directory_name}

    PermitTunnel no

    AllowAgentForwarding no

    AllowTcpForwarding no

    X11Forwarding no

  1. Restart the SFTP Service
1
2
3
    sudo systemctl restart sshd.service

  1. Testing(provide password on prompted)
1
2
3
    sftp {user_name}@{server_address}