大抵是为了文件共享吧
工具树莓派
服务端配置
用户配置
创建一个sftptest 用户,不可用于登陆
#建议用root用户登陆或者pi用户登陆由加sudo执行
cd /home
useradd -d /home/sftptest -s /bin/false sftptest
passwd sftptest //12345678
mkdir -p sftptest/get sftptest/put
chown root:sftptest sftptest/
chmod 755 sftptest/
chown sftptest:sftptest sftptest/get sftptest/put
SFTP配置
SFTP:不解释了,安装了openssh自带的,默认就安装了
修改配置文件
vim /etc/ssh/sshd_config
#屏蔽下面这一行
#Subsystem sftp /usr/libexec/openssh/sftp-server
#添加如下
Subsystem sftp internal-sftp
#匹配sftptest用户
Match User sftptest
#这个sftptest 必须是root组sftptest用户 sftp才能登陆成功,登陆后的根目录
ChrootDirectory /home/sftptest
ForceCommand internal-sftp
X11Forwarding no
重启生效
systemctl restart sshd.service
测试,如下成功
#为了方便我修改了/etc/passwd 文件使得sftptest可以登陆ssh
sftptest@raspberrypi:~/get $ sftp sftptest@127.0.0.1
Could not create directory '/home/sftptest/.ssh'.
The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:CA1enKvIsei0+IdBLSfp5lH6wtOU1nK10Sq5AjkzEqY.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/home/sftptest/.ssh/known_hosts).
sftptest@127.0.0.1's password:
Connected to sftptest@127.0.0.1.
sftp> ls
data get put
sftp> bye
FTP配置
这个自然是安装vsftpd
关于 /etc/vsftpd.conf的配置不多说,网上一搜一大堆
修改/etc/pam.d/vsftpd文件
因为我们的sftptest是禁止登陆的(/bin/false /usr/sbin/nologin等)所以要改这里
修改后大抵如下
#为了方便我修改了/etc/passwd 文件使得sftptest可以登陆ssh
sftptest@raspberrypi:~/get $ cat /etc/pam.d/vsftpd
# Standard behaviour for ftpd(8).
auth required pam_listfile.so item=user sense=deny file=/etc/ftpusers onerr=succeed
# Note: vsftpd handles anonymous logins on its own. Do not enable pam_ftp.so.
# Standard pam includes
@include common-account
@include common-session
@include common-auth
#auth required pam_shells.so
auth required pam_nologin.so
重启生效
systemctl restart vsftpd.service
测试
#为了方便我修改了/etc/passwd 文件使得sftptest可以登陆ssh
sftptest@raspberrypi:~/get $ ftp 127.0.0.1
Connected to 127.0.0.1.
220 (vsFTPd 3.0.3)
Name (127.0.0.1:pi): sftptest
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwxr-xr-x 2 0 1002 4096 Jan 17 02:45 data
drwxr-xr-x 2 1002 1002 4096 Jan 17 06:40 get
drwxr-xr-x 2 1002 1002 4096 Jan 17 06:19 put
226 Directory send OK.
ftp> bye
221 Goodbye.
SAMBA配置
安装略
sudo vim /etc/samba/smb.conf 大抵如下
#为了方便我修改了/etc/passwd 文件使得sftptest可以登陆ssh
sftptest@raspberrypi:~/get $ tail -n 25 /etc/samba/smb.conf
[movies]
comment = samba home directory
path = /samba
public = yes
browseable = yes
writeable = yes
read only = no
valid users = pi
create mask = 0777
directory mask = 0777
available = yes
[sftptest]
comment = samba home directory
path = /home/sftptest
public = yes
browseable = yes
writeable = yes
read only = no
valid user = sftptest
create mask = 0777
directory mask = 0777
available = yes
sftptest@raspberrypi:~/get $
设置一下密码 sudo smbpasswd -a sftptest
重启生效
sudo systemctl restart smbd.service
windows 映射网络驱动器 路径 \\192.168.182.128\sftptest
sftptest 就是上面中括号里面的内容
路径 \\192.168.182.128\movies 对应树莓派 /samba 登陆用户用pi , /samba的权限属于pi
客户端
安装lftp工具,wget无法支持sftp
大抵操作如下
#1.登陆
lftp ftp://sftptest:12345678@IP
lftp sftp://sftptest:12345678@IP
#2.上传
lftp -c "open sftp://sftptest:12345678@IP;cd put ;put myftp/testfile"
lftp -c "open ftp://sftptest:12345678@IP;cd put ;put myftp/testfile"
#3.下载(reget 等同于 get -c 即继续传输 )
lftp -c 'open sftp://sftptest:12345678@IP; reget get/tt -o myftp'
lftp -c 'open ftp://sftptest:12345678@IP; reget get/tt -o myftp'