August 26, 2026
Linux Capture The Flag Bandit Level 18
Bypassing a Modified .bashrc with SSH

By Red
2 min read
Bandit Level 18 is a great example of how knowing your Linux environment pays off. The challenge isn't about a complicated exploit or a long chain of tools — it's about understanding how the shell works and using that knowledge to get around a deliberate roadblock.
If you'd like to follow what I did via video, feel free to check it out on YouTube below:
The Challenge
The password for Level 18 is sitting in a file called readme in the home directory. Simple enough — except someone has modified the .bashrc file to automatically log you out the moment you log in via SSH. Every time you connect, you get booted before you can do anything.
Understanding .bashrc
The .bashrc file is a configuration file that runs automatically whenever a new bash shell session starts. It's used to set environment variables, define aliases, configure the prompt, and specify shell behavior. It's also where, in this case, a logout command has been planted to kick you out immediately on login.
There are multiple shell types in Linux — bash, sh, zsh, and others. The .bashrc file is specific to bash. If you log in using a different shell, the .bashrc doesn't execute, which means the logout command never fires.
That's the key to solving this level.
The Solution: Log In with a Different Shell
SSH allows you to specify a command or shell to run immediately upon connecting, before any configuration files for the default shell are executed. Using the -t flag followed by the shell you want to use does exactly that:
ssh bandit18@bandit.labs.overthewire.org -p 2220 -t "sh"ssh bandit18@bandit.labs.overthewire.org -p 2220 -t "sh"Breaking this down:
-tforces a pseudo-terminal allocation, allowing you to run an interactive shell"sh"tells SSH to drop you into anshshell instead of bash — bypassing.bashrcentirely
Enter the Level 18 password when prompted. Instead of being kicked out, you'll land at a shell prompt. From there, it's straightforward:
ls
cat readmels
cat readmeThe readme file contains the password for Level 19. Copy it into your notes and you're done.
Key Commands Covered
ssh user@host -p <port> -t "sh"Log in via SSH using sh instead of bash, bypassing .bashrclsList files in the current directorycat readmePrint the contents of the readme file
This level rewards breadth of Linux knowledge. The solution isn't something you'd necessarily find by just grinding through CTF challenges — it comes from actually spending time in Linux environments, understanding how shells work, and knowing what configuration files do. Resources like Linux for Hackers by OccupyTheWeb are exactly the kind of material that builds this foundation. The second edition was recently released and is well worth picking up.
Feel free to check out my blog: coderedblog.io
Checkout my YouTube
Feel free to follow me on here and keep learning!