Use OpenSSH to implement chroot prison in RedHatEnterpriseLinux6.2

Source: Internet
Author: User
We don't want the SSH Login User to browse the files in my system at will, just to fix the activity in the specified place for him. Environment: RedHatEnterpriseLinuxServerrelease6.2openssh requires 4.7p or later to create a login user that allows ssh [root @ localhost ~] # Useraddgao change the user's password [root @ localhost ~] # Passwd

We don't want the SSH Login User to browse the files in my system at will, just to fix the activity in the specified place for him.

Environment: Red Hat Enterprise Linux Server release 6.2

Openssh requires version 4.7 p or later

Create a login user that allows ssh

[Root @ localhost ~] # Useradd gao

Change User Password

[Root @ localhost ~] # Passwd gao
Changing password for user gao.
New password:
Retype new password:
Passwd: all authentication tokens updated successfully.
Create a chroot directory

[Root @ localhost ~] # Mkdir/vm/chroot

Switch to the Created directory and create the directory structure required for login.

[Root @ localhost chroot] # mdkir bin home lib64

Copy the Master Directory of the gao user to the created home directory.

[Root @ localhost chroot] # cp-r/home/gao // vm/chroot/home/

Copy the executable program and log on to bash. For more information, see copy the script 123.sh.


[Root @ localhost chroot] # cd bin/

[Root @ localhost bin] # cat 123.sh
#! /Bin/bash
Cmd = "bash touch more less awk sed vim mkdir"
For I in $ cmd
Do
A = 'which $ I'
Cp $ ./
Done
Command can be added by yourself

Copy the dependent files again. For details, refer to copy the dependent File Script 456.sh.

[Root @ localhost bin] # cd ../lib64/

[Root @ localhost lib64] # cat 456.sh
#! /Bin/bash
Cmd = "touch more less awk sed vim mkdir"
For I in $ cmd
Do
Ldd 'which $ I '| awk' {print $3} '| while read a; do cp $ a./; done
Done
Modify the ssh configuration file after all copies are completed

[Root @ localhost lib64] # vim/etc/ssh/sshd_config

Add

Match User gao
ChrootDirectory/vm/chroot

Restart the SSH service

[Root @ localhost lib64] #/etc/init. d/sshd restart

Use other machines to log in and Test

[Root @ perl ~] # Ssh gao@10.1.100.103
Gao@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 $ ls
Bin home lib64
-Bash-4.1 $

Simple chroot has been completed

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.