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