SCP on chroot ssh jail

Chroot scp

Using OpenSSH you can bind SSH, SFTP, SCP users to their home directory and restrict them to access other directories on the SSH server. In this article we will configure SCP on chroot ssh jail in the secure chroot ssh environment.


Topic

  • How to configure chroot scp on CentOS 7?
  • How to configure chroot scp on RHEL 7?
  • Chroot scp configuration on Linux
  • Chroot scp server
  • scp chroot jail
  • scp over chroot ssh


Solution


Setting up a secure or chroot ssh and scp environment requires a sandox environment which has its own libraries and binaries. In this article, we’ll bind all ssh and scp users who are part of chrootssh group into /data/chroot-ssh directory. This article has been tested on CentOS 7 and RHEL 7. You can refer to the steps given in this article to configure chroot ssh and scp on other Linux distributions.

  1. In order to setup SCP on chroot ssh jail, the prerequisite is to setup chroot SSH environment – click here.

  1. After chroot ssh environment setup is completed, execute following set of commands to get scp command working in chroot ssh sandbox environment.

  1. Remove all contents from /data/chroot-ssh/lib64 directory.
rm -rf /data/chroot-ssh/lib64/*

  1. Mount /lib64 directory at /data/chroot-ssh/lib64 directory with mount bind option.
mount --bind /lib64 /data/chroot-ssh/lib64

# To the make the above mount permanent add the following configuration in /etc/fstab file. 
/lib64                /data/chroot-ssh/lib64         -            defaults,bind       0 0

  1. Copy scp binary to /data/chroot-ssh/bin/ directory.
cp -p /usr/bin/scp /data/chroot-ssh/bin/

  1. Create a passwd and group file in /data/chroot-ssh/etc directory and then copy the specific ssh user and group information to passwd and group file in /data/chroot-ssh/etc directory.
# sample chroot ssh user is test ssh and group is chrootssh
cd /data/chroot-ssh/etc
grep chrootssh /etc/group >> group
grep testssh /etc/passwd >> passwd

  1. Now restart sshd service then test scp file transfer from the client system.

Testing

Execute the following command for ssh login and scp file transfer testing.

# SCP file transfer
$ scp  file1.txt testssh@192.168.1.1:~/
testssh@192.168.1.1's password: 
file1.txt           100%    0     0.0KB/s   00:00

# SSH Login
$ ssh testssh@192.168.1.1
testssh@192.168.1.1's password: 
-bash-4.2$ pwd
/home/testssh
-bash-4.2$ ls
file1.txt 


If you have enjoyed the above article, the following are add on articles related to SCP on chroot ssh jail:


You May Also Like

avatar

About the Author: TekFik

TekFik is a technical blogging site helps techies and engineers to solve their day to day issues and also allows everyone to share knowledge and feedback. Please feel free to contact us at tekfik.rd@gmail.com if there is anything.

Leave a Reply

Your email address will not be published. Required fields are marked *