chroot命令的主要作用是提供一个隔离的环境,使得在该环境下运行的进程无法访问到主系统的文件和目录。这样可以增加系统的安全性,防止进程对系统进行非法操作或者破坏。
一、基础环境
| 0 1 2 3 4 5 | $ uname -a Linux hk 5.14.0-514.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Mon Sep 30 14:56:52 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux $ uname -r 5.14.0-514.el9.x86_64 $ uname -m x86_64 | 
二、创建账号
| 0 1 | $ useradd developer $ echo '123456' | passwd --stdin developer  | 
三、配置SSHD
| 0 1 2 3 | $ echo 'Match User developer' >> /etc/ssh/sshd_config $ echo 'ChrootDirectory /data/chroot' >> /etc/ssh/sshd_config $ sed -i 's/^Subsystem.*$/Subsystem sftp internal-sftp/' /etc/ssh/sshd_config $ systemctl restart sshd  | 
四、权限配置
Login
五、bug fix
| 0 1 | $ \cp /etc/bashrc /data/chroot/etc/ $ chmod 1777 /data/chroot/tmp | 
六、其他说明
文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/environment/linux-env-chroot/文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/environment/linux-env-chroot/① 查找命令在系统中的实际位置,并拷贝到bin或者sbin目录下【指的是copy到chroot的bin或者sbin目录】
② 用ldd命令查找出命令运行时所依赖的共享包
③ 把这些共享包拷贝到lib64下
4️⃣ 下面的示例参考:
文 章 源 自 note.t4x.orgByrd's Blog-https://note.t4x.org/environment/linux-env-chroot/
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!
 
							
