Linux Centos7 配置Sftp服務

2021-09-26 07:29:06 字數 2799 閱讀 5772

1.規劃使用者的所屬分組和使用者的家目錄

使用者分組

家目錄uc_1

test

/sftpdir/uc/home

jctest

/sftpdir/uc/home

wj_1

test1

/sftpdir/wj/home

在這裡我新增了三個使用者分別是uc_1,jc和wj_1,同時uc_1和jc屬於同乙個test分組,而wj_1屬於test1分組.

2.接下來建立三個目錄/sftpdir /sftpdir/uc /sftpdir/wj,並設定許可權

#建立目錄/sftpdir                  mkdir  sftpdir

#設定/sftpdir所屬使用者和分組 chown root:root /sftpdir

#設定/sftpdir許可權 chmod 755 -r /sftpdir

#建立目錄/sftpdir/uc mkdir -r /sftpdir/uc

#設定/sftpdir/uc所屬使用者和分組 chown root:root /sftpdir/uc

#設定/sftpdir/uc許可權 chmod 755 -r /sftpdir/uc

#建立目錄/sftpdir/wj mkdir -r /sftpdir/wj

#設定/sftpdir/wj所屬使用者和分組 chown root:root /sftpdir/wj

#設定/sftpdir/wj許可權 chmod 755 -r /sftpdir/wj

3.建立分組test和test1

#建立test分組     groupadd   test

#建立test1分組 groupadd test1

4.建立使用者並將使用者加入所屬分組

#建立使用者uc_1         useradd  -g  test  -s  /bin/false  uc_1

#將uc_1加入test分組 usermod -g test uc_1

#建立使用者jc useradd -g test -s /bin/false jc

#將jc加入test分組 usermod -g test jc

#建立使用者wj_1 useradd -g test1 -s /bin/false wj_1

#將wj_1加入test1分組 usermod -g test1 wj_1

5.設定使用者密碼passwd

6.建立使用者目錄(uc_1和jc共用乙個目錄)

#建立uc_1和jc的使用者目錄          mkdir -r  /sftpdir/uc/home

#設定目錄許可權 chmod 775 /sftpdir/uc/home

#建立wj_1的使用者目錄 mkdir -r /sftpdir/wj/home

#設定目錄許可權 chmod 755 /sftpdir/wj/home

7.設定sshd_config檔案

(1)開啟sshd_config檔案

vi  /etc/ssh/sshd_config
(2)將這段加入檔案末尾

#subsystem sftp /usr/libexec/openssh/sftp-server

match group test1

#match user wj_1 #這行用來匹配使用者wj_1

chrootdirectory /sftpdir/wj

match group test

chrootdirectory /sftpdir/uc

x11forwarding no

allowtcpforwarding no

forcecommand internal-sftp

8.重啟sshd

systemctl  restart  sshd.service
9.用winscp測試

測試方法:

(1)在/sftpdir/home/wj目錄下建立檔案aaa,在/sftpdir/home/uc_1目錄下建立檔案bbb

(2)使用winscp分別登入三個使用者會出現如下效果

使用者wj_1登入後直接調轉到/sftpuser/wj目錄下,只能操作home裡面的內容時,可以看到home下有乙個aaa檔案(使用者uc_1和jc 不可見)

Linux centos7修改網路配置

centos 7.0預設安裝好之後是沒有自動開啟網路連線的!所以在修改網路配置的時候出現了問題。修改了網路配置檔案後,在終端ping 閘道器仍然是失敗的 然後,鍵入ifconfig 檢視網絡卡資訊 發現修改的網路配置根本沒有生效 於是,使用systemctl restart network.serv...

Linux Centos7 初始化配置

記錄下個人使用vmware安裝linux centos7使用的時候,對於初始化系統需要設定的引數。如果可以幫助到其它人更好。1 關閉防火牆,使ssh可連線 sudo systemctl stop firewalld.service sudo systemctl disable firewalld.s...

Linux CentOS7 安裝 配置 Redis

cd usr local wget tar xzvf redis 3.2.8.tar.gz 解壓完成後檢視當前目錄會多乙個redis 3.2.8資料夾 注意 可能會安裝命令 可直接安裝gcc,gcc中包含make命令 安裝make命令 yum y install make 安裝gcc yum y i...