Build an SFTP Server Using CentOS Built-in SSH Service
Source: Internet
Author: User
Keywordsssh servicesftp serversftp centos
Traditional FTP data is not secure enough, so SFTP is used to encrypt data on the server. If the SSH service is already enabled on the server, we can directly use SSH to enable the SFTP service without installing additional software.
First, create a new system account 1.1 New Account Group
Groupadd sftp
1.2 Create a new account paul useradd -s / sbin / nologin -g sftp -d / ZServer / demo
passwd paul // Set the account password
Explanation:
-s account login mode, / sbin / nologin means that this account can only log in via FTP and cannot be accessed by the system
-g sftp: account belongs to sftp group
-d: set the root directory of the account
[Requirements for directory permissions]
If you want Paul to log in with an SFTP account and successfully access the / ZServer / demo directory, the following harsh conditions need to be met. Otherwise, you will not be able to log in, and the error prompts given will be confusing and you will not be able to check them. I wasted a lot of time on it.
Ø The root directory of the account needs to belong to the account itself.
Ø The directory above the account root directory and all directories above must belong to the root account, and there is only one root with write permission, that is, the maximum permission is set to 755.
1.3 Set permissions for account root directory
#cd / ZServer /
#chown -R paul: sftp demo /
#chown -R 755 demo /
Second, SSH version:
The first step is to upgrade the OpenSSH version. Chroot is only supported in 4.8p1 and above.
Fourth, restrict the user SFTP access to the root directory
#Restrict paul user's root directory
Match User www
ChrootDirectory / ZServer
ForceCommand internal-sftp
【note】
The directory that the account paul configured to access here is restricted to a directory whose owner is root, otherwise paul will not be restricted and will lead to various errors and exceptions during login.
#Restrict the root directory of blog and pay users
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.