五月综合激情婷婷六月,日韩欧美国产一区不卡,他扒开我内裤强吻我下面视频 ,无套内射无矿码免费看黄,天天躁,日日躁,狠狠躁

新聞動(dòng)態(tài)

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

發(fā)布日期:2022-01-21 13:11 | 文章來源:站長(zhǎng)之家

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

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)來時(shí)只能進(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.測(cè)試訪問

復(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點(diǎn):

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

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

如果不能遵循以上2點(diǎn),即使是該目錄僅屬于某個(gè)用戶,也可能會(huì)影響到所有的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

然后在測(cè)試通過

復(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)限制用戶在家目錄,同時(shí)該用戶也不能登錄該機(jī)器。

版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。

相關(guān)文章

實(shí)時(shí)開通

自選配置、實(shí)時(shí)開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對(duì)1客戶咨詢顧問

在線
客服

在線客服:7*24小時(shí)在線

客服
熱線

400-630-3752
7*24小時(shí)客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部