使用openssh的新特性构建chroot环境

简介:

一、简述:
    chroot 即 change root directory (更改 root 目录) 。在 linux 系统中,系统默认的目录结构都是以 `/`,即是以根 (root) 开始的。而在使用 chroot 之后,系统的目录结构将以指定的位置作为 `/` 位置。

二、为什么要使用chroot

    在经过 chroot 之后,系统读取到的目录和文件将不在是真实系统根下的而是新根下(即被指定的新的位置)的目录结构和文件,因此它带来的好处大致有以下3个:
    * 增加了系统的安全性,限制了用户的权力;
    * 建立一个与原系统隔离的系统目录结构,方便用户的开发;
    * 可以限制chroot用户的命令使用

三、目的:可开放chroot帐号供开发人员web服务器查看日志,分析问题等。

四、chroot环境部署

如果是5.5的系统,需要升级openssh,本文是在6.2和5.5中都有使用。

#建立帐号

 
  1. useradd rd 
  2. echo "www.elain.org" | passwd --stdin rd 
#下载chroot环境
 
  1. cd /home 
  2. wget http://ebook.elain.org/tools/chroot_v1.0.tar.gz 
  3. tar zxvf chroot_v1.0.tar.gz 
  4. chown rd.rd /home/chroot/home/rd 
  5. rm -rf chroot_v1.0.tar.gz  
#注:以上是我做好的chroot环境,大家可以直接下载使用,也可以自己去做。

#启用ssh 的chroot
 
  1. cat <<EOF>>/etc/ssh/sshd_config 
  2.  
  3. #chroot 
  4. Match User rd 
  5. ChrootDirectory /home/chroot 
  6. EOF 
  7.  
  8. /etc/init.d/sshd restart 
#挂载日志目录
 
  1. mount --bind /data/logs /home/chroot/home/rd 
使用rd登录测试!!! 五、openssh升级(for centos 5.5) 1.升级sshd前准备
 
  1. yum -y install gcc* make openssl openssl-devel perl pam pam-devel 
  2. mkdir -p /opt/soft/src && cd /opt/soft/src 
  3. wget http://ftp.bit.nl/mirror/openssh/portable/openssh-5.9p1.tar.gz
#备份现有ssh
 
  1. mv /etc/ssh/ /etc/ssh.bak 
  2. cp /etc/init.d/sshd /etc/init.d/sshd.bak
2.安装sshd
 
  1. cd /opt/soft/src 
  2. tar zxf openssh-5.9p1.tar.gz 
  3. cd openssh-5.9p1 
  4. ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam --with-zlib --with-md5-passwords 
  5. make 
  6. rpm -e --nodeps openssh-server-4.3p2-41.el5 
  7. rpm -e --nodeps openssh-4.3p2-41.el5 
  8. make install 
  9. mv /etc/init.d/sshd.bak /etc/init.d/sshd 
  10. touch /etc/ssh/ssh_host_ecdsa_key 
  11. touch /etc/ssh/ssh_host_ecdsa_key.pub 
  12. mkdir -p /var/empty/sshd/etc 
#重启sshd.
 
  1. /etc/init.d/sshd restart 
升级成功.

转载请注明: 转载自http://www.elain.org

本文链接地址:使用openssh的新特性构建chroot环境



本文转自 elain2012 51CTO博客,原文链接:http://blog.51cto.com/elain/949301

相关文章
|
1月前
|
数据可视化 Linux Shell
『Linux升级路』基础开发工具——vim篇
『Linux升级路』基础开发工具——vim篇
|
4月前
|
Linux 开发工具 C语言
Linux基础环境开发工具的使用(yum,vim,gcc,g++)(中)
Linux基础环境开发工具的使用(yum,vim,gcc,g++)
|
4月前
|
Linux 编译器 开发工具
Linux基础环境开发工具的使用(yum,vim,gcc,g++)(下)
Linux基础环境开发工具的使用(yum,vim,gcc,g++)
|
4月前
|
Linux 程序员 编译器
Linux基础环境开发工具的使用(yum,vim,gcc,g++)(上)
Linux基础环境开发工具的使用(yum,vim,gcc,g++)
|
8月前
|
数据可视化 Linux 开发工具
Linux基础开发环境,yum 与 vim。
✅<1>主页:我的代码爱吃辣 📃<2>知识讲解:Linux 🔥<3>创作者:我的代码爱吃辣 💬<4>前言:Linux必不可少的基础开发环境使用。
|
10月前
|
缓存 IDE NoSQL
【Linux】Linux环境基础工具的基本使用及配置(yum、vim)(上)
【Linux】Linux环境基础工具的基本使用及配置(yum、vim)(上)
|
10月前
|
Linux Shell 程序员
【Linux】Linux环境基础工具的基本使用及配置(yum、vim)(下)
【Linux】Linux环境基础工具的基本使用及配置(yum、vim)(下)
|
Ubuntu 数据安全/隐私保护 Linux
|
测试技术 应用服务中间件 Apache