Skip to content

Commit 04deb87

Browse files
committed
chroot reorganization thanks to a suggestion by Mathieu Godlewski
1 parent d9b963a commit 04deb87

File tree

5 files changed

+51
-21
lines changed

5 files changed

+51
-21
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
chroots_dir/
2+
chroot/
3+
*.swp

custom_chroot/launch_chroot.sh renamed to launch_chroot.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ then
1212
exit 1
1313
fi
1414

15+
if [ ! -d "$root_dir" ]
16+
then
17+
echo "no chroot present, creating one"
18+
sudo ./util_create_chroot.sh
19+
sudo mv $bindir/chroots_dir/*/chroot/ $root_dir
20+
fi
21+
1522
echo "Launching chroot"
1623

1724
mountFileSystems() {
@@ -40,7 +47,7 @@ if [ ! -f $root_dir/root/.ssh/authorized_keys ]; then
4047
fi
4148

4249
launchAnsible() {
43-
ansiblePath=$bindir/chrootAnsible/ansible/
50+
ansiblePath=$bindir/ansible/
4451
source $ansiblePath/ansible_sources/hacking/env-setup
4552
ansible-playbook $ansiblePath/chroot.yml -i $ansiblePath/ansible_hosts
4653
}

readme.md

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,46 @@
11
## Setup a chroot with a SSH server running on port 220 and ready to be 'ansiblized'
22

3-
1. Create the chroot
4-
1. Launch 'sudo ./create_chroot.sh' (make sure you have debootstrap installed before)
5-
2. You will be prompted for the ubuntu distribution you want to create the chroot from
6-
3. Wait for it
7-
4. Congratulations, you have a chroot created in the chroot directory
8-
2. Use the chroot
9-
1. Now there is a directory named chroots_dir/${distrib}
10-
1. The global structure is:
11-
* chroot: contains the chroot
12-
* chrootAnsible: contains all file to customize the chroot with ansible
13-
* ansible contains the chroot.yml which is the parent yml file
14-
* launch_chroot.sh
15-
* stop_chroot.sh
16-
17-
18-
If you execute ./launch_chroot.sh it will
3+
### Prerequisites ###
4+
In order for this to work, you must have:
5+
* debootstrap
6+
* python-jinja2
7+
* python-yaml
8+
9+
For ubuntu, you can copy/paste
10+
```bash
11+
sudo apt-get install debootstrap python-jinja2 python-yaml
12+
```
13+
14+
### Usage ###
15+
Execute ./launch_chroot.sh
16+
17+
If you dont have a chroot initialized, you will be asked to chose which distribution you want to create the chroot from.
18+
At the end of the setup, ansible will be launched and your chroot configured
19+
20+
#### What the script does ####
21+
1922
* mount /proc /dev /sys and /dev/pts
2023
* launch the chroot and an ssh server
2124
* put your ssh public key to the root folder of the chroot
2225
* launch ansible
26+
* connect via ssh to the chroot
27+
28+
#### Faq ####
29+
If you have something like that:
30+
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
31+
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
32+
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
33+
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
34+
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
35+
It is also possible that a host key has just been changed.
36+
The fingerprint for the ECDSA key sent by the remote host is
37+
58:45:5b:9f:c5:33:8d:15:45:2b:81:c9:b3:28:1c:39.
38+
Please contact your system administrator.
39+
Add correct host key in /home/yourhome/.ssh/known_hosts to get rid of this message.
40+
Offending ECDSA key in /home/yourhome/.ssh/known_hosts:13
41+
remove with: ssh-keygen -f "/home/yourhome/.ssh/known_hosts" -R [127.0.0.1]:220
42+
ECDSA host key for [127.0.0.1]:220 has changed and you have requested strict checking.
43+
Host key verification failed.
2344

24-
Once this is over, you have your prompt back and you can connect to the chroot by using 'ssh root@localhost -p 220'.
45+
it means that you probably had another system running on port 220.
46+
To get rid of this message, simply run the ssh-keygen command promped by the message. In my case, this will be 'ssh-keygen -f "/home/yourhome/.ssh/known_hosts" -R [127.0.0.1]:220', stop your chroot and launch it again.
File renamed without changes.

create_chroot.sh renamed to util_create_chroot.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ echo "------------------- USAGES ------------------"
44
echo "-- create a minimun chroot based on ubuntu --"
55
echo "------------------- USAGES ------------------"
66

7+
cd $(dirname $0)
8+
79
readonly base_chroots_dir="chroots_dir"
810

911
get_path_to_chroot() {
@@ -61,8 +63,6 @@ customize_chroot() {
6163
fi
6264
sudo sed -i 's/Port 22$/Port 220/' ${chroot_dir}/etc/ssh/sshd_config
6365
sudo rm -rf ${chroot_dir}/var/cache/apt/archives/*.deb
64-
sudo cp custom_chroot/stop_chroot.sh ${chroot_dir}/../
65-
sudo cp custom_chroot/launch_chroot.sh ${chroot_dir}/../
6666
sudo cp custom_chroot/init_ssh.sh ${chroot_dir}/
6767
sudo mkdir ${chroot_dir}/root/.ssh/
6868

@@ -74,7 +74,6 @@ customize_chroot() {
7474
sudo echo "TZ='Europe/Paris'; export TZ" >> bash.bashrc
7575
sudo mv bash.bashrc ${chroot_dir}/etc/bash.bashrc
7676
sudo chmod 644 ${chroot_dir}/etc/bash.bashrc
77-
sudo git clone --recursive https://github.com/MichaelBitard/chrootAnsible.git ${base_chroots_dir}/${distrib}/chrootAnsible
7877
}
7978
finishChroot() {
8079
local distrib=$1

0 commit comments

Comments
 (0)