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.

Mar 28, 2025 - 11:47
Updated: 
109.6k

Security Tools, Authorized Labs & CTFs in Cybersecurity & Ethical Hacking · Lab / project

Ethical Hacking, Penetration Testing, AI in Cybersecurity

How to Use ShellGPT in Kali Linux: Install, Examples and Safe Practice

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?

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?

OptionHowNote
Session variableexport OPENAI_API_KEY in the current shellGone when the terminal closes
Config file~/.config/shell_gpt/.sgptrcSet chmod 600 on the file
Hard-coded in scriptsAvoidLeaks 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?

TaskExample
Explain a commandsgpt 'explain what ss -ltnp shows'
Suggest a commandsgpt --shell 'show disk usage by folder in /var/log'
Draft codesgpt --code 'bash script to rotate a log file'
Summarise outputjournalctl -u ssh --since today | sgpt 'summarise failed logins'
Keep contextsgpt --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

An open source command-line assistant, run as sgpt, that sends prompts to a language model and returns answers, commands or code.

Kali marks its Python as externally managed under PEP 668. Use pipx install shell-gpt to install it in an isolated environment.

In the OPENAI_API_KEY environment variable or in the ShellGPT config file with restricted permissions, never inside scripts or repositories.

With the shell option it suggests a command and asks before executing. Always read the command yourself before you confirm it.

Not client results. Prompts go to the API provider, so client data, credentials and personal data should be kept out.

The project documents other back ends such as local models, but its README warns they are not optimised and may behave differently.

It can explain Linux commands and concepts while you study, but you still need to understand and verify everything yourself.

If you installed it with pipx, run pipx upgrade shell-gpt, then check sgpt --help because options can change between releases.

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Wow Wow 0
Sad Sad 0
Angry Angry 0
Vaishnavi

Vaishnavi is a skilled tech professional at the Ethical Hacking Training Institute in Pune, responsible for managing and optimizing the technical infrastructure that supports advanced cybersecurity education. With deep expertise in network security, backend operations, and system performance, she ensures that practical labs, online modules, and assessments run smoothly and securely. Her behind-the-scenes contributions play a vital role in delivering a seamless and secure learning experience for aspiring ethical hackers.