it-wiki:linux:ssh_chrooted_jail
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
| it-wiki:linux:ssh_chrooted_jail [2021/03/10 18:28] – [Step 3: Create and Configure SSH User] marko | it-wiki:linux:ssh_chrooted_jail [2021/03/10 21:06] (aktuell) – [Step 7. Testing SFTP with Chroot Jail] marko | ||
|---|---|---|---|
| Zeile 18: | Zeile 18: | ||
| # ls -l / | # ls -l / | ||
| </ | </ | ||
| - | {{ : | + | {{ : |
| **3.** Now, create the ''/ | **3.** Now, create the ''/ | ||
| Zeile 29: | Zeile 29: | ||
| # mknod -m 666 random c 1 8 | # mknod -m 666 random c 1 8 | ||
| </ | </ | ||
| - | {{ : | + | {{ : |
| **4.** Afterwards, set the appropriate permission on the chroot jail. Note that the chroot jail and its subdirectories and subfiles must be owned by **root** user, and not writable by any normal user or group: | **4.** Afterwards, set the appropriate permission on the chroot jail. Note that the chroot jail and its subdirectories and subfiles must be owned by **root** user, and not writable by any normal user or group: | ||
| Zeile 37: | Zeile 37: | ||
| # ls -ld /home/test | # ls -ld /home/test | ||
| </ | </ | ||
| - | {{ : | + | {{ : |
| ==== Step 2: Setup Interactive Shell for SSH Chroot Jail ==== | ==== Step 2: Setup Interactive Shell for SSH Chroot Jail ==== | ||
| Zeile 45: | Zeile 45: | ||
| # cp -v /bin/bash / | # cp -v /bin/bash / | ||
| </ | </ | ||
| - | {{ : | + | {{ : |
| **6.** Now, identify bash required shared '' | **6.** Now, identify bash required shared '' | ||
| Zeile 53: | Zeile 53: | ||
| # cp -v / | # cp -v / | ||
| </ | </ | ||
| - | {{ : | + | {{ : |
| ==== Step 3: Create and Configure SSH User ==== | ==== Step 3: Create and Configure SSH User ==== | ||
| Zeile 67: | Zeile 67: | ||
| # cp -vf / | # cp -vf / | ||
| </ | </ | ||
| - | {{ : | + | {{ : |
| **<color red> | **<color red> | ||
| ==== Step 4: Configure SSH to Use Chroot Jail ==== | ==== Step 4: Configure SSH to Use Chroot Jail ==== | ||
| - | 9. Now, open the '' | + | **9.** Now, open the '' |
| <code bash> | <code bash> | ||
| # vi / | # vi / | ||
| </ | </ | ||
| + | |||
| + | and add/modify the lines below in the file. | ||
| + | <code bash> | ||
| + | #define username to apply chroot jail to | ||
| + | Match User tecmint | ||
| + | #specify chroot jail | ||
| + | ChrootDirectory /home/test | ||
| + | </ | ||
| + | {{ : | ||
| + | |||
| + | Save the file and exit, and restart the SSHD services: | ||
| + | <code bash> | ||
| + | # systemctl restart sshd | ||
| + | </ | ||
| + | |||
| + | ==== Step 5: Testing SSH with Chroot Jail ==== | ||
| + | **10.** At this point, test if the chroot jail setup is working as expected: | ||
| + | <code bash> | ||
| + | # ssh tecmint@192.168.0.10 | ||
| + | -bash-4.1$ ls | ||
| + | -bash-4.1$ date | ||
| + | -bash-4.1$ uname | ||
| + | </ | ||
| + | {{ : | ||
| + | |||
| + | From the screenshot above, we can see that the SSH user is locked in the chrooted jail, and can’t run any external commands (ls, date, uname etc). | ||
| + | |||
| + | The user can only execute bash and its builtin commands such as(pwd, history, echo etc) as seen below: | ||
| + | <code bash> | ||
| + | # ssh tecmint@192.168.0.10 | ||
| + | -bash-4.1$ pwd | ||
| + | -bash-4.1$ echo " | ||
| + | -bash-4.1$ history | ||
| + | </ | ||
| + | {{ : | ||
| + | |||
| + | ==== Step 6. Create SSH User’s Home Directory and Add Linux Commands ==== | ||
| + | **11.** From the previous step, we can notice that the user is locked in the root directory, we can create a home directory for the the SSH user like so (do this for all future users): | ||
| + | <code bash> | ||
| + | # mkdir -p / | ||
| + | # chown -R tecmint: | ||
| + | # chmod -R 0700 / | ||
| + | </ | ||
| + | {{ : | ||
| + | |||
| + | **12.** Next, install a few user commands such as ls, date, mkdir in the '' | ||
| + | <code bash> | ||
| + | # cp -v /bin/ls / | ||
| + | # cp -v /bin/date / | ||
| + | # cp -v /bin/mkdir / | ||
| + | </ | ||
| + | {{ : | ||
| + | |||
| + | **13.** Next, check the shared libraries for the commands above and move them into the chrooted jail libraries directory: | ||
| + | <code bash> | ||
| + | # ldd /bin/ls | ||
| + | # cp -v / | ||
| + | </ | ||
| + | {{ : | ||
| + | |||
| + | ==== Step 7. Testing SFTP with Chroot Jail ==== | ||
| + | **14.** Do a final test using sftp; check if the commands you have just installed are working. | ||
| + | |||
| + | Add the line below in the ''/ | ||
| + | <code bash> | ||
| + | #Enable sftp to chrooted jail | ||
| + | ForceCommand internal-sftp | ||
| + | </ | ||
| + | |||
| + | Save the file and exit. Then restart the SSHD services: | ||
| + | <code bash> | ||
| + | # systemctl restart sshd | ||
| + | </ | ||
| + | |||
| + | **15.** Now, test using SSH, you’ll get the following error: | ||
| + | <code bash> | ||
| + | # ssh tecmint@192.168.0.10 | ||
| + | </ | ||
| + | {{ : | ||
| + | |||
| + | Try using SFTP as follows: | ||
| + | < | ||
| + | # sftp tecmint@192.168.0.10 | ||
| + | </ | ||
| + | {{ : | ||
| + | |||
it-wiki/linux/ssh_chrooted_jail.1615400919.txt.gz · Zuletzt geändert: von marko