国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Linux > 正文

Linux上設(shè)置用戶通過SFTP訪問目錄的權(quán)限的方法

2020-07-10 11:09:19
字體:
供稿:網(wǎng)友

 sftp和ftp是兩種協(xié)議是不同的,sftp是ssh內(nèi)含的協(xié)議,只要sshd服務(wù)器啟動了,它就可用,它本身不需要ftp服務(wù)器啟動。

1.查看openssh軟件版本,想sftp服務(wù)用戶只能訪問特定的文件目錄,版本需要4.8以上

復(fù)制代碼
代碼如下:

[root@localhost ftp]# rpm -qa | grep openssh
openssh-server-5.3p1-81.el6_3.x86_64
openssh-5.3p1-81.el6_3.x86_64
openssh-clients-5.3p1-81.el6_3.x86_64

2.新增用戶,限制用戶只能通過sftp訪問

復(fù)制代碼
代碼如下:

[root@localhost ftp]# useradd -m -d /opt/ftp/dave -s /sbin/nologin dave

3.限制用戶通過sftp登錄進(jìn)來時只能進(jìn)入主目錄,修改/etc/ssh/sshd_config文件

復(fù)制代碼
代碼如下:

[root@localhost ftp]# vim /etc/ssh/sshd_config
#Subsystem sftp /usr/libexec/openssh/sftp-server
Subsystem sftp internal-sftp
Match User dave
ChrootDirectory /opt/ftp/dave
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp

重啟ssh
4.測試訪問

復(fù)制代碼
代碼如下:

root@10.1.1.200:test# sftp -oPort=22 dave@10.1.6.175
Connecting to 10.1.6.175...
dave@10.1.6.175's password:
Read from remote host 10.1.6.175: Connection reset by peer
Couldn't read packet: Connection reset by peer

發(fā)現(xiàn)連接不上,查看日志

復(fù)制代碼
代碼如下:

[root@localhost ftp]# tail /var/log/messages
Jan 6 11:41:41 localhost sshd[4907]: fatal: bad ownership or modes for chroot directory "/opt/ftp/dave"
Jan 6 11:41:41 localhost sshd[4905]: pam_unix(sshd:session): session closed for user dave

解決方法:

目錄權(quán)限設(shè)置上要遵循2點:

ChrootDirectory設(shè)置的目錄權(quán)限及其所有的上級文件夾權(quán)限,屬主和屬組必須是root;

ChrootDirectory設(shè)置的目錄權(quán)限及其所有的上級文件夾權(quán)限,只有屬主能擁有寫權(quán)限,權(quán)限最大設(shè)置只能是755。

如果不能遵循以上2點,即使是該目錄僅屬于某個用戶,也可能會影響到所有的SFTP用戶。

復(fù)制代碼
代碼如下:

[root@localhost ftp]# ll
total 4
drwxr-xr-x 3 dave dave 4096 Jan 5 13:06 dave
[root@localhost ftp]# chown root:root dave
[root@localhost ftp]# chmod 755 dave
[root@localhost ftp]# ll
total 4
drwxr-xr-x 3 root root 4096 Jan 5 13:06 dave

然后在測試通過

復(fù)制代碼
代碼如下:

root@10.1.1.200:test# sftp -oPort=22 dave@10.1.6.175
Connecting to 10.1.6.175...
dave@10.1.6.175's password:
sftp> ls
test
sftp> cd ..
sftp> ls
test
sftp> cd test
sftp> ls
1.txt
sftp> get 1.txt
Fetching /test/1.txt to 1.txt
/test/1.txt

可以看到已經(jīng)限制用戶在家目錄,同時該用戶也不能登錄該機器。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 克山县| 临泉县| 仁寿县| 东山县| 宁远县| 抚远县| 淳化县| 深圳市| 福海县| 兴业县| 兴仁县| 雅安市| 浦县| 盐亭县| 邵武市| 穆棱市| 拜城县| 大田县| 迁西县| 锦屏县| 阿克陶县| 得荣县| 瓦房店市| 西和县| 汉阴县| 巧家县| 临汾市| 罗城| 克东县| 黔南| 石景山区| 长丰县| 扶余县| 北川| 乳山市| 定远县| 华容县| 胶南市| 临安市| 监利县| 贵定县|