国产宅男网站在线|亚洲A级性爱免费视频|亚洲中精品级在线|午夜福利AA毛

  • <dd id="gf5jf"><th id="gf5jf"></th></dd>

    <cite id="gf5jf"><label id="gf5jf"></label></cite>
  • <div id="gf5jf"><listing id="gf5jf"></listing></div>
    學(xué)習(xí)啦>學(xué)習(xí)電腦>操作系統(tǒng)>Linux教程>

    Linux怎么設(shè)置用戶通過(guò)SFTP訪問(wèn)目錄的權(quán)限

    時(shí)間: 春健736 分享

      眾所周知SFTP賬號(hào)是基于SSH賬號(hào)的,所以在默認(rèn)情況下訪問(wèn)服務(wù)器的權(quán)限是非常大的。就讓學(xué)習(xí)啦小編來(lái)告訴大家Linux怎么設(shè)置用戶通過(guò)SFTP訪問(wèn)目錄的權(quán)限的方法吧,希望對(duì)大家有所幫助。

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

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

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

      代碼如下:

      [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.新增用戶,限制用戶只能通過(guò)sftp訪問(wèn)

      代碼如下:

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

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

      代碼如下:

      [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è)試訪問(wèn)

      代碼如下:

      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)連接不上,查看日志

      代碼如下:

      [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用戶。

      代碼如下:

      [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è)試通過(guò)

      代碼如下:

      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ī)器。

    看過(guò)“Linux怎么設(shè)置用戶通過(guò)SFTP訪問(wèn)目錄的權(quán)限”的人還看了:

    1.LINUX操作系統(tǒng)如何更改用戶或組

    2.如何限制Linux用戶的訪問(wèn)權(quán)限

    3.Linux如何利用訪問(wèn)控制列表來(lái)限制用戶權(quán)限

    4.windows7怎么改用戶名

    5.Linux系統(tǒng)中怎么限制用戶su-權(quán)限

    6.Linux怎么配置Web服務(wù)器

    1095114