How to Use ShellGPT in Kali Linux: Install, Examples and Safe Practice
ShellGPT is an open source command-line assistant, run as sgpt, that sends your prompt to a large language model and prints an answer, a suggested shell command or code. On Kali Linux, install it with pipx install shell-gpt, because Kali blocks system-wide pip installs under PEP 668. Provide your API key through the OPENAI_API_KEY environment variable or the ShellGPT config file, never in scripts or shared notes.
Topic: Security Tools, Authorized Labs & CTFs in Cybersecurity & Ethical Hacking · Lab / project
Also covers: Ethical Hacking, Penetration Testing, AI in Cybersecurity
Quick answer: ShellGPT is an open source command-line assistant, run as sgpt, that sends your prompt to a large language model and prints an answer, a suggested shell command or code. On Kali Linux, install it with pipx install shell-gpt, because Kali blocks system-wide pip installs under PEP 668. Provide your API key through the OPENAI_API_KEY environment variable or the ShellGPT config file, never in scripts or shared notes. Use it to explain commands, draft scripts and summarise output, but read every suggested command before running it, and never paste passwords, keys or client data into a prompt.
Key takeaways
- ShellGPT is a prompt-to-command helper, not a hacking tool.
- Install with pipx to respect Kali's managed Python environment.
- Keep the API key in an environment variable or protected config.
- Prompts leave your machine, so keep secrets and client data out.
- Review suggested commands; the model can be wrong.
Table of Contents
- What Is ShellGPT and How Does It Work?
- How Do You Install ShellGPT on Kali Linux?
- How Should You Store the API Key?
- What Are Useful Everyday Examples?
- Why Must You Review Every Suggested Command?
- What Data Should Never Go Into a Prompt?
- How Does ShellGPT Fit Into Security Learning?
- References
What Is ShellGPT and How Does It Work?
ShellGPT is maintained on GitHub and published as the shell-gpt package. It calls an OpenAI-compatible API by default; the project also documents other back ends, with a warning that local models may not work as well. For background, see our earlier explainer on what ShellGPT is.
How Do You Install ShellGPT on Kali Linux?
Kali marks its Python as externally managed (PEP 668), so plain pip install fails. pipx installs the tool in its own environment:
sudo apt update
sudo apt install pipx
pipx ensurepath
pipx install shell-gpt
sgpt --help
Open a new terminal after pipx ensurepath so the PATH change applies. Upgrade later with pipx upgrade shell-gpt.
How Should You Store the API Key?
| Option | How | Note |
|---|---|---|
| Session variable | export OPENAI_API_KEY in the current shell | Gone when the terminal closes |
| Config file | ~/.config/shell_gpt/.sgptrc | Set chmod 600 on the file |
| Hard-coded in scripts | Avoid | Leaks through Git and backups |
To avoid saving the key in shell history, read it without echo:
read -rs OPENAI_API_KEY && export OPENAI_API_KEY
chmod 600 ~/.config/shell_gpt/.sgptrc
OpenAI's API key safety guidance also recommends separate keys per use and spending limits.
What Are Useful Everyday Examples?
| Task | Example |
|---|---|
| Explain a command | sgpt 'explain what ss -ltnp shows' |
| Suggest a command | sgpt --shell 'show disk usage by folder in /var/log' |
| Draft code | sgpt --code 'bash script to rotate a log file' |
| Summarise output | journalctl -u ssh --since today | sgpt 'summarise failed logins' |
| Keep context | sgpt --chat notes 'continue from the previous answer' |
With --shell, ShellGPT shows the command and asks before executing it. Check your version with sgpt --help, since flags can change between releases.
Why Must You Review Every Suggested Command?
Language models can produce commands that are wrong, outdated or destructive, such as a recursive delete in the wrong folder. The OWASP Top 10 for LLM Applications lists overreliance and insecure output handling as risks. Treat each suggestion like code from a stranger: read it, check the man page, and try it in a snapshot VM first.
What Data Should Never Go Into a Prompt?
- Passwords, API keys, tokens and private keys.
- Client IP ranges, hostnames, scan results or reports.
- Personal data covered by India's DPDP Act 2023.
- Anything your contract or rules of engagement keep confidential.
Piping logs into sgpt sends them to the provider, so redact first. The NIST AI RMF is a good reference for organisational AI policies.
How Does ShellGPT Fit Into Security Learning?
It helps learners understand Linux commands and draft small scripts faster, but it does not replace knowing what a command does. Testing any system still needs written authorisation under India's IT Act 2000. Compare it with other assistants in our post on Kali GPT, and ask about WebAsha Kali Linux and ethical hacking training.
References
Frequently Asked Questions
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Wow
0
Sad
0
Angry
0