# Supercharge Your Terminal: Configuring ShellGPT on Linux with ChatGPT-4o and Ollama

# **Introduction**

ShellGPT also known as sgpt, a command-line productivity tool powered by AI large language model (LLM) designed to assist users in generating and executing shell commands.

It leverages the advanced capabilities of GPT (Generative Pre-Trained Transfomer) technology to bring AI -powered assistance directly to the terminal, whether you are a beginner or professional it simplifies complex tasks by enabling that natural language interactions, script automation, and command optimization with the growing importance in AI in cybersecurity.

# **Key Features**

1. **Command Assistants**: Suggests and generates shell commands based on plain language input.
    
2. **Code Generation:** Generates scripts (e.g., Bash, Python) or snippets based on user requests.
    
3. **Automation and Task Simplification:** Automates workflows, like setting up environments, scheduling cron jobs, or configuring server settings.
    
4. **Integration with APIs**: Can integrate with APIs(ChatGPT-4o, llama)or tools (like Git, Docker, AWS CLI) to provide tailored suggestions or automate interactions.
    
5. **Real-Time System Insights:** Retrieves real-time system data (e.g., CPU usage, memory, network stats) using GPT-based insights to guide users on optimizing performance.
    
6. **Secure and Offline Options**: This option can be configured to run locally (using models like Ollama or other offline GPT instances), ensuring sensitive data does not leave the environment.
    

Shell gpt is a **game changer** for ethical hackers and cybersecurity professionals offering numerous benefits that enhance efficiency accessibility and overall workflow.

# **Step-by-step installation guide for the shell-gpt:**

Create a separate directory for easy installation eg: I’m setting it on my desktop directory

```bash
cd Desktop 

mkdir sgpt 

cd sgpt 


Now, you are in the folder /home/Kali/Desktop/sgpt
```

1. **Install python and its package manager pip.**
    

I) Install Python :

ShellGPT requires Python 3.8 or later. If you don’t have already have Python installed, follow these steps:

```bash
python3 --version  //Check if Python is installed (Optional)

sudo apt update 
sudo apt install python3 python3-pip
```

II) Install pip :

pip is a package manager for python, ensure it is installed and up to date.

```bash
python3 -m pip install --upgrade pip
```

2\. I)**Create virtual environment to run shellgpt :**

Creating a virtual environment (venv) in python is essential for maintaining a clean, isolated workspace for your projects.

```bash
python3 -m venv sgpt


python3: Specifies the Python interpreter to use.
-m venv: Invokes the venv module to create a virtual environment.
sgpt : Name of that virtual environment where we do our task
```

II) Activate a Python virtual environment named sgpt

```bash
source sgpt/bin/activate
```

Environment should look like this :

![](https://miro.medium.com/v2/resize:fit:700/1*8kUafNtkOWxNJBf1Pf23MQ.png align="left")

3\. **Install ShellGPT**

```bash
pip install shell-gpt
```

By default, ShellGPT uses OpenAI’s API and GPT-4 model. You’ll need an API key, you can generate one [here](https://platform.openai.com/api-keys).

![](https://miro.medium.com/v2/resize:fit:700/1*mhJnDo-VMhuTVvP-M3TYDA.png align="left")

4\. **Set your openAI API Key**

After getting the key, set automatically every time a new terminal session starts. This avoids the need to set the key manually each time.

```bash
echo 'export OPENAI_API_KEY=sk-proj-<rest_of_key>' >> ~/.bashrc
```

![](https://miro.medium.com/v2/resize:fit:700/1*6asDCyU7QKstmacaqjQ8gg.png align="left")

Ensure that the sgpt is ready to use

```bash
sgpt --version
```

![](https://miro.medium.com/v2/resize:fit:700/1*PIdIeZXHZW99zdHsM_HPhA.png align="left")

if you get this output be sure that you have successfully configured shellgpt integrated with the openAI (chatGPT-4o)

*Note: OpenAI API is not free of charge, please refer to the* [***OpenAI pricing***](https://openai.com/api/pricing/) *for more information.*

**Alternatively**, you can use a locally hosted open-source model and run your own LLM backend server such as [***Ollama***](https://ollama.com/download/linux)

Now again a step-by-step guide to using sgpt with the llama model

1. Go to [***ollama***](https://ollama.com/download/linux) ***and*** copy this and paste it on your terminal
    

```bash
curl -fsSL https://ollama.com/install.sh | sh
```

![](https://miro.medium.com/v2/resize:fit:700/1*Ka3cXc711eNj2n1EkbJtjA.png align="left")

you downloaded ollama for linux now you need to install it’s model as your requirement.

2\. Download its model as your requirement :

Go to [search](https://ollama.com/search) model and choose your model, let’s choose [llama3.2](https://ollama.com/library/llama3.2:3b) with its 3b model and download it as shown

![](https://miro.medium.com/v2/resize:fit:700/1*N8oRduoWi1uhYBadGEllpQ.png align="left")

you will see success and you could easily interact with ollama.

Now when we have Ollama backend running we need to configure ShellGPT to use it. To communicate with local LLM backends, ShellGPT utilizes LiteLLM. To install it run:

```apache
pip install shell-gpt[litellm]
```

now you are ready to run the free ollama model and to avoids the need to run the model manually each time we change some of the configuration of the file.

***Go to this path:*** *sudo nano ~/.config/shell\_gpt/.sgptrc*

change the following requirements

```apache
DEFAULT_MODEL=ollama/llama3.2:3b  //Your downloaded model
 OPENAI_USE_FUNCTIONS=false
 USE_LITELLM=true
 OPENAI_APT_KEY=123456 //It's a random number
```

After this, you are ready to use shellgpt on your terminal.

*Note: If you encountered some system problem then try adding RAM on your system or download the small model which could resist your computer system.*

```bash
sgpt "who are you"
```

![](https://miro.medium.com/v2/resize:fit:700/1*oh8soE2JppobNF1bx3RewQ.png align="left")

or you can query with code too: *sgpt -c “your prompt”*

Not only this you could get more features with shellgpt you can explore though this link [SHELLGPT](https://github.com/TheR1D/shell_gpt?tab=readme-ov-file). some of them are

1. Shell commands :
    
2. Shell integration
    
3. Generating code
    
4. Chat Mode
    
5. REPL Mode
    
6. Function calling
    
7. Roles
    
8. Request cache
    

Here are the [arguments](https://github.com/TheR1D/shell_gpt?tab=readme-ov-file#full-list-of-arguments) for using shellGPT.
