一、创建sftp相关用户和目录

[root@mail samba]# useradd -s /sbin/nologin -M sftp_user #创建一个系统用户,按需设置登录的shell和家目录
[root@mail samba]# passwd sftp_user #设置密码,也是sftp登录的密码,公网上尽可能复杂点 [root@mail samba]# mkdir /var/sftp/sftp_user -pv #创建sftp的根目录
[root@mail samba]# chown root:root -R /var/sftp/sftp_user #将属组和属主都设置为root,必须,这里最容易出错
[root@mail sftp_user]# cd /var/sftp/sftp_user/
[root@mail sftp_user]# mkdir public #创建共享目录
[root@mail sftp_user]# chown sftp_user:sftp_user -R /var/sftp/sftp_user/public/ #将共享目录的属组属主设为我们的sftp用户

二、编辑sshd配置文件,内容如下

#   $OpenBSD: sshd_config,v 1.80 // :: djm Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config() for more information. # This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin # The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options change a
# default value. #Port
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress :: # Disable legacy (protocol version ) support in the server for new
# installations. In future the default will change to require explicit
# activation of protocol
Protocol 2 #支持的SSH协议的版本号 # HostKey for protocol version
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key # Lifetime and size of ephemeral version server key
#KeyRegenerationInterval 1h
#ServerKeyBits # Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV #将日志消息通过哪个日志子系统(facility)发送
#LogLevel INFO # Authentication: #LoginGraceTime 2m
#PermitRootLogin yes
#StrictModes yes
#MaxAuthTries
#MaxSessions #RSAAuthentication yes
#PubkeyAuthentication yes
#AuthorizedKeysFile .ssh/authorized_keys
#AuthorizedKeysCommand none
#AuthorizedKeysCommandRunAs nobody # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#RhostsRSAAuthentication no
# similar for protocol version
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes # To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication yes #允许通过密码进行登录 # Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no #是否允许质疑-应答(challenge-response)认证。默认值是"yes"。 # Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
#KerberosUseKuserok yes # GSSAPI options
#GSSAPICleanupCredentials yes
GSSAPICleanupCredentials yes #是否在用户退出登录后自动销毁用户凭证缓存。默认值是"yes"。仅用于SSH-2。
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no # Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
#UsePAM no
UsePAM yes #是否启用pam认证 # Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES #指定客户端发送的哪些环境变量将会被传递到会话环境中。[注意]只有SSH-2协议支持环境变量的传递,可以设置多个
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS #AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding no
X11Forwarding yes #是否允许进行 X11 转发。默认值是"no",设为"yes"表示允许
#X11DisplayOffset
#X11UseLocalhost yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval
#ClientAliveCountMax
#ShowPatchLevel no
#PidFile /var/run/sshd.pid
#MaxStartups ::
#PermitTunnel no
#ChrootDirectory none # no default banner path
#Banner none # override default of no subsystems
#Subsystem sftp /usr/libexec/openssh/sftp-server
Subsystem sftp internal-sftp #配置一个外部子系统,仅用于SSH-2协议。值是一个子系统的名字和对应的命令行(含选项和参数)。比如"sftp /usr/libexec/openssh/sftp-server"。,###这里配置为内部的
# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# ForceCommand cvs server
GSSAPIAuthentication no #是否允许使用基于 GSSAPI 的用户认证。默认值为"no"。仅用于SSH-2。
UseDNS no #是否对远程主机名进行反向解析
AllowTcpForwarding yes #是否允许TCP转发
Compression yes #是否对通信数据进行加密,还是延迟到认证成功之后再对通信数据加密
MaxAuthTries 6 #指定每个连接最大允许的认证次数。默认值是 6
PermitRootLogin yes #是否允许 root 登录
PrintMotd yes #是否在每一次交互式登录时打印 /etc/motd 文件的内容
PubkeyAuthentication yes #是否允许公钥认证。仅可以用于SSH-2。默认值为"yes"。
RSAAuthentication no #是否允许使用纯 RSA 公钥认证。仅用于SSH-1。默认值是"yes" Match User sftp_user #对特定的用户单独配置,匹配到的用户会强制使用/bin/false shell,只能以sftp登录,无法使用ssh登录服务器,没有匹配到的用户或组可以直接sftp登录,但是根目录为自己的家目录,无法指定具体的根目录。也可以设置为组,例如:Match Group sftp 
ChrootDirectory  /var/sftp/sftp_user/ #限定用户的根目录
X11Forwarding no
AllowTcpForwarding yes
ForceCommand internal-sftp #强制执行这里指定的命令而忽略客户端提供的任何命令

 重启sshd服务

[root@mail sftp_user]# /etc/init.d/sshd restart
停止 sshd: [确定]
正在启动 sshd: [确定]

测试登录,这里使用winscp这款软件

输入我们之前设置的密码

登录成功

Centos6搭建sftp服务器的更多相关文章

  1. Linux Centos 6.6搭建SFTP服务器

    Linux Centos 6.6搭建SFTP服务器 在Centos 6.6环境使用系统自带的internal-sftp搭建SFTP服务器. 打开命令终端窗口,按以下步骤操作. 0.查看openssh的 ...

  2. freeSSHD在windows环境下搭建SFTP服务器

    freeSSHD在windows环境下搭建SFTP服务器 0 建议现在windows环境下安装cygwin,否则在windows环境下cmd模式使用不了sftp去连接,可以利用win scp去测试连接 ...

  3. Linux ---搭建SFTP服务器

    在Centos 6.6环境使用系统自带的internal-sftp搭建SFTP服务器. 打开命令终端窗口,按以下步骤操作. 0.查看openssh的版本 ssh -V 使用ssh -V 命令来查看op ...

  4. windows 上搭建 sftp 服务器 -freesshd全过程( 在linux上部署逐浪CMS的必读教程)

    文章标题: windows 上搭建 sftp 服务器 - freesshd全过程 关键字 : freesshd 文章分类: 教程 创建时间: 2020年3月23日 缘由 动手 第一步:添加用户 第二步 ...

  5. linux搭建sftp服务器

    转自:http://blog.csdn.net/superswordsman/article/details/49331539 最近工作需要用到sftp服务器,被网上各种方法尤其是权限设置问题搞得晕头 ...

  6. Windows搭建SFTP服务器

    1.项目需要搭建一个SFTP服务器,网上搜了一下,用的是freeSSHd软件,网上查一下我用的是1.3.1版本https://freesshd.updatestar.com/网址自己下载即可. 2.安 ...

  7. 搭建SFTP服务器,允许一个或多个用户拥有一个或多个目录的rwx权限

    1.引言 sftp可以为传输文件提供一种安全的网络的加密方法.sftp 与 ftp 有着几乎一样的语法和功能.SFTP 为 SSH的其中一部分,是一种传输档案至 Blogger 伺服器的安全方式.其实 ...

  8. CentOS6搭建OpenVPN服务器

    一.服务器端安装及配置 服务器环境:干净的CentOS6.3 64位系统 内网IP:10.143.80.116 外网IP:203.195.xxx.xxx OpenVPN版本:OpenVPN 2.3.2 ...

  9. linux如何搭建sftp服务器

    工具/原料   centos7.2_x64 方法/步骤   创建sftp组 groupadd sftp 创建完成之后使用cat /etc/group命令组的信息   2 创建一个sftp用户mysft ...

随机推荐

  1. js获取谷歌浏览器版本

    根据浏览器的useragent获取浏览器信息 // 获取谷歌浏览器版本 function getChromeVersion() { var arr = navigator.userAgent.spli ...

  2. fedora liveuser 切换root;su -l root

    安装完Fedora 14后,默认没有启用sudo,首先应该是对sudo进行设置.sudo的作用就是使当前非root用户在使用没有权限的命令时,直接在命令前加入sudo,在输入自己当前用户的密码就可以完 ...

  3. UVa 10382 - Watering Grass 贪心,水题,爆int 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  4. 【阅读笔记】《C程序员 从校园到职场》第六章 配置文件,makefile 文件 (Part 2)

     Contents: 1.配置文件(通常以 ini 结尾) 2.makefile文件 (Linux) PS: 这篇文章的内容,不太理解. 一.配置文件 本文以一个实际的小软件为例,介绍了C语言中配置文 ...

  5. python全栈开发笔记----基本数据类型---列表方法

    #list 类中提供的方法 #参数 1.def append(self, *args, **kwargs)原来值最后追加#对象..方法(..) #li对象调用append方法 li = [11,22, ...

  6. ARTS(一)

    ARTS第一周,2019年3月17日,星期日,天气晴. A:算法学习(Algorithm) 将一个给定字符串根据给定的行数,以从上往下.从左到右进行 Z 字形排列. 比如输入字符串为 "LE ...

  7. oracle密码过期的修改

    ALTER USER 用户名 IDENTIFIED BY 密码 ;

  8. HBase和Phoneix使用示例

    HBase操作 基本操作 创建表 Examples: hbase> create 't1', {NAME => 'f1', VERSIONS => 5} hbase> crea ...

  9. ORA-00847: MEMORY_TARGET/MEMORY_MAX_TARGET and LOCK_SGA cannot be set together

    群里有位兄弟,测试系统修改sga_lock=true参数后,重启库报错 ORA-00847: MEMORY_TARGET/MEMORY_MAX_TARGET and LOCK_SGA cannot b ...

  10. Spring boot JPA 用自定义主键策略 生成自定义主键ID

    最近学习Spring boot JPA 学习过程解决的一些问题写成随笔,大家一起成长.这次遇到自定义主键的问题 package javax.persistence; public enum Gener ...