1、环境
名称 | ip |
---|---|
server | 192.168.1.1 |
client | 192.168.1.2 |
2、服务器创建repl用户
useradd -m -d /home/repl -s /usr/sbin/nologin repl
3、修改密码
passwd repl
4、ssh配置
# 该行不注释
Subsystem sftp /usr/libexec/openssh/sftp-server
# 增加一下行
Match User repl
AllowTcpForwarding no
PasswordAuthentication yes
X11Forwarding no
ForceCommand internal-sftp
ChrootDirectory /data/backup
5、重启ssh服务
systemctl restart sshd
6、测试从client端ssh登录server端
ssh [email protected]
# 提示报错
This service allows sftp connections only.
7、测试从client端sftp登录server端
sftp [email protected]
8、脚本实现自动备份
#!/bin/bash
DATE=`date +%F`
home="/data/config/"
sshpass -p 'Repl@123#' sftp -oBatchMode=no -oport=22 [email protected] << !
lcd $home
mkdir date
cd date
put $DATE.tar.gz
bye
!
标签:1.1,192.168,sftp,repl,ssh,Linux,server
From: https://www.cnblogs.com/wacxpan/p/17899185.html