当前位置:网站首页>Contos 7 搭建sftp之创建用户、用户组以及删除用户
Contos 7 搭建sftp之创建用户、用户组以及删除用户
2022-07-01 18:43:00 【无极小卒】
1、添加新用户并设置配置文件
# 创建sftp系统用户并禁用ssh登录
useradd -s /sbin/nologin sftp1
#设置或修改sftp1登录
echo "[email protected]" |passwd --stdin sftp1
# 配置sshd_config
vi /etc/ssh/sshd_config
找到如下这行,用#符号注释掉。
# Subsystem sftp /usr/libexec/openssh/sftp-server
# 在文件最后面添加如下几行内容
Subsystem sftp internal-sftp
#匹配用户
Match User sftp1
ChrootDirectory /data/sftp/sftp1
ForceCommand internal-sftp
AllowTcpForwarding no # 非必须
X11Forwarding no # 非必须
#设定Chroot目录权限(必须),用户目录以及组目录以及数据根目录都要设置为755 权限,不要太高,否则可能报Permission denied的异常
mkdir -p /data/sftp/sftp1
chown root:root /data/sftp/sftp1
chmod 755 /data -R
#建立SFTP用户登入后可写入的目录upload
mkdir /data/sftp/sftp1/upload
chown sftp1 /data/sftp/sftp1/upload
#给upload以及下级文件授权777,否则可能报Permission denied的异常
chmod 777 /data/sftp/sftp1/upload -R
#重新启动 sshd 服务:
systemctl restart sshd.service最后使用flashfxp输入账号sftp1 ,密码: [email protected] 登录即可。
2、添加用户组以及用户并设置配置文件
#创建用户组sftp以及新用户sftp1
groupadd sftp
adduser sftp1
#将用户添加到用户组
useradd -G sftp -s /sbin/nologin sftp1
#设置该用户密码
passwd [email protected]
#禁止该用户shell登录
usermod -s /bin/false sftp1
#设置sshd_config
vi /etc/ssh/sshd_config
找到如下这行,用#符号注释掉。
# Subsystem sftp /usr/libexec/openssh/sftp-server
#找到 Subsystem sftp 这一行,修改成:
Subsystem sftp internal-sftp
Match Group sftp
UsePAM yes
#用chroot将用户的根目录指定到%h,%h代表用户home目录,这样用户 就只能在用户目录下活动。也可用%u,%u代表用户名
ChrootDirectory /data/sftp/%u
ForceCommand internal-sftp
AllowTcpForwarding no
X11Forwarding no
#设定Chroot目录权限(必须),用户目录sftp1以及组目录sftp以及数据根目录data都要设置为755 权限,不要太高,否则可能报Permission denied的异常
mkdir -p /data/sftp/sftp1
chown root:root /data/sftp/sftp1
chmod 755 /data -R
#建立SFTP用户登入后可写入的目录upload
mkdir /data/sftp/sftp1/upload
chown sftp1 /data/sftp/sftp1/upload
#给upload以及下级文件授权777,否则可能报Permission denied的异常
chmod 777 /data/sftp/sftp1/upload -R
#重新启动 sshd 服务:
systemctl restart sshd.service
最后使用flashfxp输入账号sftp1 ,密码: [email protected] 登录即可。
3、删除用户并重新创建用户
#如果已有用户,清除掉
userdel sftp1
rm -rf /home/sftp1
rm -rf /var/spool/mail/sftp1
#新建sftp组、具体用户sftp1
groupadd sftp
adduser sftp1
useradd -G sftp -s /sbin/nologin sftp1
passwd [email protected]
#修改ssh配置文件
vi /etc/ssh/sshd_config
找到如下这行,用#符号注释掉。
#Subsystem sftp /usr/libexec/openssh/sftp-server
Subsystem sftp internal-sftp
UsePAM yes
#用chroot将用户的根目录指定到%h,%h代表用户home目录,这样用户 就只能在用户目录下活动。也可用%u,%u代表用户名
ChrootDirectory /data/sftp/%u
ForceCommand internal-sftp
AllowTcpForwarding no
X11Forwarding no
#设定Chroot目录权限(必须),用户目录以及组目录以及数据根目录都要设置为755 权限,不要太高,否则可能报Permission denied的异常
mkdir -p /data/sftp/sftp1
chown root:root /data/sftp/sftp1
chmod 755 /data -R
#建立SFTP用户登入后可写入的目录upload
mkdir /data/sftp/sftp1/upload
chown sftp1 /data/sftp/sftp1/upload
#给upload以及下级文件授权777,否则可能报Permission denied的异常
chmod 777 /data/sftp/sftp1/upload -R
#重启ssh
service sshd restart
最后使用flashfxp输入账号sftp1 ,密码: [email protected] 登录即可。
边栏推荐
- CDGA|从事通信行业,那你应该考个数据管理证书
- ES6 summary "suggestions collection" of array methods find(), findindex()
- Lake Shore低温恒温器的氦气传输线
- 机械设备行业数字化供应链集采平台解决方案:优化资源配置,实现降本增效
- Lake Shore—OptiMag 超导磁体系统 — OM 系列
- Openai video pre training (VPT): action learning based on watching unmarked online videos
- ACM mm 2022 video understanding challenge video classification track champion autox team technology sharing
- Lumiprobe 亚磷酰胺丨六甘醇亚磷酰胺说明书
- Lake Shore continuous flow cryostat transmission line
- Create your own NFT collections and publish a Web3 application to show them (Introduction)
猜你喜欢

Create your own NFT collections and publish a Web3 application to show them (Introduction)

The market value evaporated by 74billion yuan, and the big man turned and entered the prefabricated vegetables

Viewing the whole ecology of Tiktok from a macro perspective

Solidity - 合约结构 - 错误(error)- ^0.8.4版本新增

Altair HyperWorks 2022 software installation package and installation tutorial

小红书上的爱情买卖

【快应用】text组件里的文字很多,旁边的div样式会被拉伸如何解决

More information about M91 fast hall measuring instrument

Lake Shore—CRX-EM-HF 型低温探针台

AI training speed breaks Moore's law; Song shuran's team won the RSS 2022 Best Paper Award
随机推荐
Dom4J解析XML、Xpath检索XML
精耕渠道共谋发展 福昕携手伟仕佳杰开展新产品培训大会
Example explanation: move graph explorer to jupyterlab
The best landing practice of cave state in an Internet ⽹⾦ financial technology enterprise
Lake shore M91 fast hall measuring instrument
[live broadcast appointment] database obcp certification comprehensive upgrade open class
Is PMP cancelled??
[6.24-7.1] review of wonderful technical blog posts in the writing community
The difference between indexof and includes
制造业SRM管理系统供应商全方位闭环管理,实现采购寻源与流程高效协同
June issue | antdb database participated in the preparation of the "Database Development Research Report" and appeared on the list of information technology and entrepreneurship industries
nacos配置文件发布失败,请检查参数是否正确的解决方案
Cache problems after app release
[pytorch record] distributed training dataparallel and distributeddataparallel of the model
Helium transmission line of lake shore cryostat
【Go ~ 0到1 】 第四天 6月30 defer,结构体,方法
More information about M91 fast hall measuring instrument
SuperOptiMag 超导磁体系统 — SOM、SOM2 系列
【直播预约】数据库OBCP认证全面升级公开课
Altair HyperWorks 2022 software installation package and installation tutorial