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 20:39] – [Step 4: Configure SSH to Use Chroot Jail] marko | it-wiki:linux:ssh_chrooted_jail [2021/03/10 21:06] (aktuell) – [Step 7. Testing SFTP with Chroot Jail] marko | ||
---|---|---|---|
Zeile 72: | Zeile 72: | ||
==== 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 / | ||
Zeile 92: | Zeile 92: | ||
==== Step 5: Testing SSH with Chroot Jail ==== | ==== Step 5: Testing SSH with Chroot Jail ==== | ||
- | '' | + | **10.** At this point, test if the chroot jail setup is working as expected: |
<code bash> | <code bash> | ||
# ssh tecmint@192.168.0.10 | # ssh tecmint@192.168.0.10 | ||
Zeile 104: | Zeile 104: | ||
The user can only execute bash and its builtin commands such as(pwd, history, echo etc) as seen below: | 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.1615408768.txt.gz · Zuletzt geändert: von marko