<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Nischal's Blog]]></title><description><![CDATA[Nischal's Blog]]></description><link>https://blog.nischalpariyar.com.np</link><generator>RSS for Node</generator><lastBuildDate>Sat, 16 May 2026 15:23:26 GMT</lastBuildDate><atom:link href="https://blog.nischalpariyar.com.np/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Supercharge Your Terminal: Configuring ShellGPT on Linux with ChatGPT-4o and Ollama]]></title><description><![CDATA[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-Tra...]]></description><link>https://blog.nischalpariyar.com.np/supercharge-your-terminal-configuring-shellgpt-on-linux-with-chatgpt-4o-and-ollama</link><guid isPermaLink="true">https://blog.nischalpariyar.com.np/supercharge-your-terminal-configuring-shellgpt-on-linux-with-chatgpt-4o-and-ollama</guid><category><![CDATA[shellgpt]]></category><category><![CDATA[#cybersecurity]]></category><category><![CDATA[AI]]></category><category><![CDATA[chatgpt]]></category><category><![CDATA[technology]]></category><category><![CDATA[Artificial Intelligence]]></category><category><![CDATA[Security]]></category><dc:creator><![CDATA[Nischal Pariyar]]></dc:creator><pubDate>Mon, 06 Jan 2025 05:13:56 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1736140259133/06fd8577-6459-41cc-a3a6-f9033a4b6816.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-introduction"><strong>Introduction</strong></h1>
<p>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.</p>
<p>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.</p>
<h1 id="heading-key-features"><strong>Key Features</strong></h1>
<ol>
<li><p><strong>Command Assistants</strong>: Suggests and generates shell commands based on plain language input.</p>
</li>
<li><p><strong>Code Generation:</strong> Generates scripts (e.g., Bash, Python) or snippets based on user requests.</p>
</li>
<li><p><strong>Automation and Task Simplification:</strong> Automates workflows, like setting up environments, scheduling cron jobs, or configuring server settings.</p>
</li>
<li><p><strong>Integration with APIs</strong>: Can integrate with APIs(ChatGPT-4o, llama)or tools (like Git, Docker, AWS CLI) to provide tailored suggestions or automate interactions.</p>
</li>
<li><p><strong>Real-Time System Insights:</strong> Retrieves real-time system data (e.g., CPU usage, memory, network stats) using GPT-based insights to guide users on optimizing performance.</p>
</li>
<li><p><strong>Secure and Offline Options</strong>: 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.</p>
</li>
</ol>
<p>Shell gpt is a <strong>game changer</strong> for ethical hackers and cybersecurity professionals offering numerous benefits that enhance efficiency accessibility and overall workflow.</p>
<h1 id="heading-step-by-step-installation-guide-for-the-shell-gpt"><strong>Step-by-step installation guide for the shell-gpt:</strong></h1>
<p>Create a separate directory for easy installation eg: I’m setting it on my desktop directory</p>
<pre><code class="lang-bash"><span class="hljs-built_in">cd</span> Desktop 

mkdir sgpt 

<span class="hljs-built_in">cd</span> sgpt 


Now, you are <span class="hljs-keyword">in</span> the folder /home/Kali/Desktop/sgpt
</code></pre>
<ol>
<li><strong>Install python and its package manager pip.</strong></li>
</ol>
<p>I) Install Python :</p>
<p>ShellGPT requires Python 3.8 or later. If you don’t have already have Python installed, follow these steps:</p>
<pre><code class="lang-bash">python3 --version  //Check <span class="hljs-keyword">if</span> Python is installed (Optional)

sudo apt update 
sudo apt install python3 python3-pip
</code></pre>
<p>II) Install pip :</p>
<p>pip is a package manager for python, ensure it is installed and up to date.</p>
<pre><code class="lang-bash">python3 -m pip install --upgrade pip
</code></pre>
<p>2. I)<strong>Create virtual environment to run shellgpt :</strong></p>
<p>Creating a virtual environment (venv) in python is essential for maintaining a clean, isolated workspace for your projects.</p>
<pre><code class="lang-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 <span class="hljs-built_in">where</span> we <span class="hljs-keyword">do</span> our task
</code></pre>
<p>II) Activate a Python virtual environment named sgpt</p>
<pre><code class="lang-bash"><span class="hljs-built_in">source</span> sgpt/bin/activate
</code></pre>
<p>Environment should look like this :</p>
<p><img src="https://miro.medium.com/v2/resize:fit:700/1*8kUafNtkOWxNJBf1Pf23MQ.png" alt /></p>
<p>3. <strong>Install ShellGPT</strong></p>
<pre><code class="lang-bash">pip install shell-gpt
</code></pre>
<p>By default, ShellGPT uses OpenAI’s API and GPT-4 model. You’ll need an API key, you can generate one <a target="_blank" href="https://platform.openai.com/api-keys">here</a>.</p>
<p><img src="https://miro.medium.com/v2/resize:fit:700/1*mhJnDo-VMhuTVvP-M3TYDA.png" alt /></p>
<p>4. <strong>Set your openAI API Key</strong></p>
<p>After getting the key, set automatically every time a new terminal session starts. This avoids the need to set the key manually each time.</p>
<pre><code class="lang-bash"><span class="hljs-built_in">echo</span> <span class="hljs-string">'export OPENAI_API_KEY=sk-proj-&lt;rest_of_key&gt;'</span> &gt;&gt; ~/.bashrc
</code></pre>
<p><img src="https://miro.medium.com/v2/resize:fit:700/1*6asDCyU7QKstmacaqjQ8gg.png" alt /></p>
<p>Ensure that the sgpt is ready to use</p>
<pre><code class="lang-bash">sgpt --version
</code></pre>
<p><img src="https://miro.medium.com/v2/resize:fit:700/1*PIdIeZXHZW99zdHsM_HPhA.png" alt /></p>
<p>if you get this output be sure that you have successfully configured shellgpt integrated with the openAI (chatGPT-4o)</p>
<p><em>Note: OpenAI API is not free of charge, please refer to the</em> <a target="_blank" href="https://openai.com/api/pricing/"><strong><em>OpenAI pricing</em></strong></a> <em>for more information.</em></p>
<p><strong>Alternatively</strong>, you can use a locally hosted open-source model and run your own LLM backend server such as <a target="_blank" href="https://ollama.com/download/linux"><strong><em>Ollama</em></strong></a></p>
<p>Now again a step-by-step guide to using sgpt with the llama model</p>
<ol>
<li>Go to <a target="_blank" href="https://ollama.com/download/linux"><strong><em>ollama</em></strong></a> <strong><em>and</em></strong> copy this and paste it on your terminal</li>
</ol>
<pre><code class="lang-bash">curl -fsSL https://ollama.com/install.sh | sh
</code></pre>
<p><img src="https://miro.medium.com/v2/resize:fit:700/1*Ka3cXc711eNj2n1EkbJtjA.png" alt /></p>
<p>you downloaded ollama for linux now you need to install it’s model as your requirement.</p>
<p>2. Download its model as your requirement :</p>
<p>Go to <a target="_blank" href="https://ollama.com/search">search</a> model and choose your model, let’s choose <a target="_blank" href="https://ollama.com/library/llama3.2:3b">llama3.2</a> with its 3b model and download it as shown</p>
<p><img src="https://miro.medium.com/v2/resize:fit:700/1*N8oRduoWi1uhYBadGEllpQ.png" alt /></p>
<p>you will see success and you could easily interact with ollama.</p>
<p>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:</p>
<pre><code class="lang-apache"><span class="hljs-attribute">pip</span> install shell-gpt[litellm]
</code></pre>
<p>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.</p>
<p><strong><em>Go to this path:</em></strong> <em>sudo nano ~/.config/shell_gpt/.sgptrc</em></p>
<p>change the following requirements</p>
<pre><code class="lang-apache"><span class="hljs-attribute">DEFAULT_MODEL</span>=ollama/llama<span class="hljs-number">3</span>.<span class="hljs-number">2</span>:<span class="hljs-number">3</span>b  //Your downloaded model
 <span class="hljs-attribute">OPENAI_USE_FUNCTIONS</span>=false
 <span class="hljs-attribute">USE_LITELLM</span>=true
 <span class="hljs-attribute">OPENAI_APT_KEY</span>=<span class="hljs-number">123456</span> //It's a random number
</code></pre>
<p>After this, you are ready to use shellgpt on your terminal.</p>
<p><em>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.</em></p>
<pre><code class="lang-bash">sgpt <span class="hljs-string">"who are you"</span>
</code></pre>
<p><img src="https://miro.medium.com/v2/resize:fit:700/1*oh8soE2JppobNF1bx3RewQ.png" alt /></p>
<p>or you can query with code too: <em>sgpt -c “your prompt”</em></p>
<p>Not only this you could get more features with shellgpt you can explore though this link <a target="_blank" href="https://github.com/TheR1D/shell_gpt?tab=readme-ov-file">SHELLGPT</a>. some of them are</p>
<ol>
<li><p>Shell commands :</p>
</li>
<li><p>Shell integration</p>
</li>
<li><p>Generating code</p>
</li>
<li><p>Chat Mode</p>
</li>
<li><p>REPL Mode</p>
</li>
<li><p>Function calling</p>
</li>
<li><p>Roles</p>
</li>
<li><p>Request cache</p>
</li>
</ol>
<p>Here are the <a target="_blank" href="https://github.com/TheR1D/shell_gpt?tab=readme-ov-file#full-list-of-arguments">arguments</a> for using shellGPT.</p>
]]></content:encoded></item></channel></rss>