利用openssh實現chroot監牢

來源:互聯網
上載者:User


利用openssh實現chroot監牢 我們不想讓SSH 登陸的使用者隨意瀏覽我系統的檔案,只給他固定在指定地方活動。 環境:Red Hat Enterprise Linux Server release 6.2 openssh 需要4.7p 以上版本 建立一個允許ssh的登陸使用者 [root@localhost ~]# useradd  gao 更改使用者的密碼  www.2cto.com   [root@localhost ~]# passwd gaoChanging password for user gao.New password:Retype new password:passwd: all authentication tokens updated successfully.建立chroot目錄 [root@localhost ~]# mkdir /vm/chroot 切換到建好的目錄下,再建立登陸需要的目錄結構 [root@localhost chroot]# mdkir bin home lib64 把gao使用者的主目錄拷貝到剛剛建好的home下 [root@localhost chroot]# cp -r /home/gao/ /vm/chroot/home/ 拷貝可執行程式和登陸bash,參考拷貝執行程式指令碼123.sh [root@localhost chroot]# cd bin/ [root@localhost bin]# cat 123.sh#!/bin/bashcmd="bash touch more less awk sed vim mkdir"for i in $cmddo        a=`which $i`        cp $a ./done命令可以自行添加  www.2cto.com   再拷貝執行依賴的檔案,參考拷貝依賴檔案指令碼456.sh [root@localhost bin]# cd ../lib64/ [root@localhost lib64]# cat 456.sh#!/bin/bashcmd="touch more less awk sed vim mkdir"for i in $cmddo        ldd `which $i` |awk '{print $3}'|while read a ;do cp $a ./;donedone全部拷貝完成後修改ssh 的設定檔  www.2cto.com   [root@localhost lib64]# vim /etc/ssh/sshd_config 在其最後加上 Match User gaoChrootDirectory /vm/chroot 重啟SSH服務 [root@localhost lib64]# /etc/init.d/sshd restart 使用其他機器登陸測試  www.2cto.com   [root@perl ~]# ssh gao@10.1.100.103gao@10.1.100.103's password:Last login: Wed Oct 10 11:54:00 2012 from 10.1.100.104-bash-4.1$ cd /-bash-4.1$ pwd/-bash-4.1$ lsbin  home  lib64-bash-4.1$ 簡單的chroot 已經完成

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.