Configure the SFTP environment for non-SSH users in Linux

Source: Internet
Author: User

Configure the SFTP environment for non-SSH users in Linux

InSome EnvironmentsThe system administrator wants to allow a very small number of users to transfer files to Linux machines, but does not allow SSH. To achieve this goal, we can useSFTPAnd build a chroot environment for it.

SFTP & chroot Background:

SFTPYesSSH File Transfer protocol (SSH File Transfer Protocol) or Secure File Transfer protocol (Secure File Transfer Protocol)It provides file access, file transmission, and file management functions under trusted data streams. After we configure the chroot environment for SFTP, only authorized users can access it and are restricted to theirHome DirectoryIn other words, licensed users will be in a cage environment where they cannot even switch their directories.

In this article, we will configureRHEL 6.XAndSFTP Chroot environment in CentOS 6. X. We open a user account'Jack', This user is allowed to transfer files on Linux machines, but has no ssh access permission.

Step: 1. Create a group

 
 
  1. [root@localhost ~]# groupadd  sftp_users  

Step 2: Assign the affiliated group (sftp_users) to the user

If the user does not exist on the system, use the following command to create LCTT. Note: a shell that cannot be logged on is specified to prevent ssh logon ):

 
 
  1. [root@localhost ~]# useradd  -G sftp_users  -s /sbin/nologin  jack  
  2. [root@localhost ~]# passwd jack  

ForExisting User, Use the following usermod command to modify:

 
 
  1. [root@localhost ~]# usermod –G sftp_users  -s /sbin/nologin  jack  

Note:: If you want to modifyDefault home directoryYou can use'-D'Option, and setAppropriate Permissions.

Step: 3 edit the configuration file "/etc/ssh/sshd_config"

 
 
  1. # vi /etc/ssh/sshd_config  
  2. #comment out the below line and add a line like below  
  3. #Subsystem sftp /usr/libexec/openssh/sftp-server  
  4. Subsystem sftp internal-sftp  
  5.  
  6. # add Below lines  at the end of file  
  7.   Match Group sftp_users  
  8.   X11Forwarding no  
  9.   AllowTcpForwarding no  
  10.   ChrootDirectory %h                        
  11.   ForceCommand internal-sftp 

Here:

  • Match Group sftp_users-This parameter specifies that the following rows only match users in the sftp_users group.
  • ChrootDirectory % h-This parameter specifies the default user's home directory for the chroot environment path after user authentication ). For user Jack, the path is/home/jack.
  • ForceCommand internal-sftp-This parameter enforces internal sftp and ignores any ~ Commands in the/. ssh/rc file.

Restart the ssh service

 
 
  1. # service sshd restart 

Step 4. Set permissions:

 
 
  1. [root@localhost ~]# chmod 755 /home/jack  
  2. [root@localhost ~]# chown root /home/jack  
  3. [root@localhost ~]# chgrp -R sftp_users /home/jack  

If you want to allow jack to upload files, create an upload folder and set the following permissions:

 
 
  1. [root@localhost jack]# mkdir /home/jack/upload  

  2. [root@localhost jack]# chown jack. /home/jack upload/  

Step: 5 now try to access the system and Test

Try to access the system through ssh

As shown in, user jack logs on through SFTP, And the directory cannot be switched because of the chroot environment.

Proceed nowUpload and downloadTest, such:

As shown in, jack's upload and download functions work well.

Via: http://www.linuxtechi.com/configure-chroot-sftp-in-linux/

Author: Pradeep Kumar Translator: GOLinux Proofreader: wxy

Http://linux.cn/article-3692-1.html.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.