Get the App
SLTechnology News&Howtos  ›  Servers  › 

Combing the process of adding sftp users to linux

Shulou Source: shulou.com Published: 2022-06-02 07:35:22 10月03日 Update

Sometimes, for special needs, the server needs to activate sftp to transfer files to the peer server instead of ftp. Write this as follows:

Operating system linux

1. Add new users

Useradd-g sftponly-s "/ bin/false"-d "/ ftp/usftpuser/" usftpuser

2 、 / etc/ssh/sshd_config

Modify

Subsystem sftp internal-sftp

UsePAM yes

New matching users

Match User usftpuser

ChrootDirectory / ftp/usftpuser

X11Forwarding no

AllowTcpForwarding no

ForceCommand internal-sftp

Note: the / ftp/usftpuser/,usftpuser directory here must be a root user with 755 permissions, otherwise it cannot be used.

Service sshd restart

Then you can try to log in:

[root@cpsvpn ~] # sftp usftpuser@193.168.4.30

Connecting to 193.168.4.30...

Usftpuser@193.168.4.30's password:

Sftp >

Sftp >

Sftp > ls

Sftp >

Sftp > pwd

Remote working directory: /

Note: if the user usftpuser needs to use the current directory, there must be an administrative root to establish a directory with permissions, otherwise it cannot be used.

Tags: Users directories servers permissions services special operating systems functions files systems requirements transfer attempts login management processes Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Docker Shulou Technology Huawei Apple