sh 设置sftp用户

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 设置sftp用户相关的知识,希望对你有一定的参考价值。

# set up SFTP (https://devtidbits.com/2011/06/29/implement-a-sftp-service-for-ubuntudebian-with-a-chrooted-isolated-file-directory/) 
# install openssh-server

  sudo apt-get install openssh-server

# add new group

  sudo groupadd sftpconnect

# get new group's id

  cat /etc/group

# add new user

  sudo useradd sftpuser -d / -g [sftpconnect group id] -M -N -o -u [sftpconnect group id]
  # -d is the user home directory which needs to be set to / (root)
  # -g is the user group id to assign
  # -M stops the useradd command creating a home directory
  # -N stops the useradd command creating a group with the same name as the new user
  # -u is the user id, which in our case needs to be the same id value as sftpconnect
  # -o allows duplicate, non-unique user ids

# set password
  
  sudo passwd sftpuser

# change in /etc/ssh/sshd_config

  Subsystem sftp /usr/lib/openssh/sftp-server
  # to
  Subsystem sftp internal-sftp

# add this to the end of the file

  Match group sftpconnect     # assigns the following rules to members of sftpconnect
  ChrootDirectory /var/www    # change root directory
  X11Forwarding no            # disables X11 forwarding
  AllowTcpForwarding no       # disables TCP forwarding
  ForceCommand internal-sftp  # forces internal-sftp

# set permissions and ownership for the root driectory just set up for sftp

	sudo chmod -R 755 /var/www permission
	sudo chmod -R 755 /var/www/html permission
	sudo chown -R root:sftpconnect /var/www/html

# and restart

  sudo service ssh restart

以上是关于sh 设置sftp用户的主要内容,如果未能解决你的问题,请参考以下文章

sh 使用ProFTPd(带有SFTP模块)为密钥验证设置SSH密钥

sh 创建一个用户并限制他到他的家庭目录(sftp)

sftp用户权限设置

Linux设置SFTP服务用户目录权限

Linux设置SFTP服务用户目录权限

Linux设置SFTP服务用户目录权限