Table of Contents
  • Home
  • /
  • Blog
  • /
  • Bring AI on Your Terminal- Learn How to Integrate Your Terminal with AI Using Shell GPT
December 15, 2023
|
10m

Bring AI on Your Terminal- Learn How to Integrate Your Terminal with AI Using Shell GPT


Bring Ai On Your Terminal Learn How To Integrate Your Terminal With Ai Using Shell Gpt

Now, AI is everywhere. It’s the new normal. You can’t leave without AI. If you ignore AI technologies and keep yourselves away from AI technologies,  you will be left behind, nobody will care for you, and you will be thrown out to nowhere from this highly competitive world. If you want to be here, learn to adopt AI technologies in your daily life.

It’s a known fact, that we begin with the command line and move to GUI as technology progress, remember first-generation computers? The other fact is. no matter how much we develop the GUI, we still use command-line or terminal even today. Even today, most of the high-level tasks are being carried out on CLI.. Most of the servers run on the terminal or command line even today. This proves how powerful the CLI is.

Undeniably, the CLI is more powerful then GUI. Wait, there are some challenges too. Command line terminals are not user-friendly, you can’t use a terminal without technical knowledge. However, since the development of AI and LLMs, many advancements happened. Technology has stepped into a new generation. The same applied to Terminal users as well.

Now, the technology has grown to the level that anybody can integrate AI and LLMs with their command line and be more productive then ever before. We created this post to help all terminal users especially the security professionals, irrespective of platforms, to get their job done even more efficiently. We will show you how to bring AI to the terminal using a small but powerful AI tool called Shell GPT.

The Common Challenges of Using CLI

Upon spending more than one and half decades in IT, I even struggled to use the command line interface. Especially, when I have to work on different OS terminals simultaneously. And, when I want to use any specific command line tools, I can’t work without its documentation or help page. Being a security professional I have listed some common challenges of using CLI here and I will also show you how those challenges can be

mitigated by integrating the terminal with an AI LLM tool called Shell GPT later in the blog post.

  1. Remembering Commands and Flags: With the wide variety of CLI tools, remembering the specific commands, options, flags, and syntax for each one becomes very difficult. I often have to refer to cheat sheets or documentation for even basic commands.

  2. Managing Multiple Environments: Working across Linux, Windows, macOS, and other environments requires context switching. The commands, flags and output can vary widely across different shells. This increases complexity and lead to end up in confusion.

  3. Discoverability of Capabilities: Within each CLI tool’s set of commands, discovering what subset of functionality is actually supported often feels like digging through layers of documentation. Visual overviews of capabilities are lacking.

  4. Managing Data Output: The output from CLI tools is raw text data that requires piping through grep, awk, sort, and other filters to parse. Interpreting and deriving insights from CLI output requires significant scripting skills.

  5. Chaining Commands: Building complex operations requires chaining together multiple simple commands with proper inputs and outputs flowing between them. Getting these pipelines configured correctly can be tricky.

  6. Automating Repetitive Tasks: While the automation strengths of CLI are powerful, scripting workflows with tools like Bash requires programming knowledge many users lack. I am the one among them.

However, having the powerful tools like Shell GPT and PowerGPT, now it has become easy to manage these challenges. Before we go and see how, let’s lean about Shell GPT.

What is Shell GPT?

Shell GPT is a command-line productivity tool powered by large language models (LLMs), specifically GPT-3 and GPT-4. It is designed to assist developers, security professionals, system administrators, or anyone who uses terminal in various tasks related to shell commands, code generation, documentation, and more. Shell GPT leverages AI capabilities to provide accurate and context-aware responses directly within the terminal, reducing the need for external searches and reference materials.

You can use it in shell mode, code mode, conversation mode, chat mode, RPL mode etc. It can help generate commands, understand and execute commands, write code, solve queries and more.

Key features of Shell GPT include:

  1. Shell Commands: Shell GPT can generate and execute shell commands based on user queries, making it easier to perform common tasks in the terminal.

  2. Code Generation: It can generate code snippets in various programming languages, helping developers and security professionals with coding tasks and providing solutions to the problems.

  3. Troubleshooting: Shell GPT can provide documentation and explanations for code, commands, or concepts, making it a useful tool for learning and troubleshooting.

  4. Custom Roles: Users can create custom roles to tailor the tool to their specific needs, whether it’s generating code, providing shell commands, or other tasks.

  5. Conversational Modes: Shell GPT supports conversational modes, allowing users to interact with the AI model in a chat-like manner, making it easy to preserve and recall conversations.

  6. Local AI Support: It offers the flexibility to use locally hosted models, reducing dependency on external services and potentially allowing offline use.

  7. Docker Container: Shell GPT can be run in a Docker container, simplifying deployment and usage.

  8. Request Cache: It caches previous responses, enabling faster access to previously requested information.

  9. Runtime Configuration: Users can customize various parameters and settings in the runtime configuration file.

Shell GPT is a versatile tool that can assist developers, security professionals, and users in a wide range of tasks within the command-line environment, from generating code to finding solutions and explanations for various queries.

How this Tool Helps Security Professionals and Pen-testers?

Cybersecurity is a cross-platform entity, which needs to keep its figurines on every technology. This makes the security professionals learn many technologies. Which is impossible. Shell GPT helps security professionals to use multiple technologies without learning them. So, Shell GPT can be a great tool for security professionals and penetration testers.

It helps generate tailored commands for various hacking and security testing purposes like WiFi cracking, port scanning etc. This saves significant time in crafting these commands manually. Additionally, Shell GPT provides detailed descriptions of what each command does when prompted. This helps pen testers quickly learn and get explanations of complex one-liners without needing to look them up externally.

Another major advantage is that Shell GPT writes full exploit code and scripts on demand if asked to generate code for a particular task like network scanning. Writing these from scratch would take up precious pen testing time. Furthermore, Shell GPT allows instantly executing the commands and scripts it generates right within the terminal which accelerates the speed of pen testing operations.

Shell GPT supercharges the terminal with OpenAI’s GPT knowledge which can greatly assist security researchers in automating tedious tasks. The time savings and instant code generation makes their job much faster and more productive.

Now, we learn about Shell GPT and its usage. Let’s see how to install this tool on a Linux machine to transform your boring terminal into a next-generation AI-powered terminal.

How to Install Shell GPT and Integrate Your Terminal with AI?

Shell GPT is a Python tool and is available as a pip model. So, it can be installed on any platform which has Python and Pip installed. To say about its prerequisites, you need these basic things:

  • You need to have Python and pip installed on your system. You can download Python from the official website and pip is typically included with Python installation. If not, you can install it by running this command.

    • Linux: sudo apt install python3-pip

    • Mac: sudo easy_install pip

  • You’ll also need an OpenAI API key, which you can generate by signing up for an OpenAI account.

  • Access to the pubic network to interact with OpenAI’s API endpoint.

We are going to install the Shell GPT on our Kali Linux VM, however you can do this on any Windows, Linux, or Mac machines.

Step 1: Ensure you have Python and Pip installed on your machine

As we said earlier, Shell GPT is a Python tool and available as pip repository. You should have Python and Pip installed on your machine. Since Python is part of basic package installation in most Linux distributions, you no need to install Python on Linux. For Windows, yes. You should install Python and Pip.

Please check out these two posts to learn how to install Python and Pycharm on Windows:

Step-by-Step Procedure to Install Python on Windows

Step-by-Step Procedure to Install PyCharm on Windows

If you are not sure your PC has Python installed, run this command:

python --version
Pip --version

Step 2: Install Shell GPT

Since Shell GPT is available on Pip repository, run this pip install command to install Shell-GPT on your machine.

sudo python3 -m pip install shell-gpt

Step 3: Configure API Key

OpenAPI key is mandatory to run the Shell GPT. You need to sign in to OpenAI and generate an API key. Export the key as $OPENAI_API_KEY environment variablerunning this export command. 

export OPENAI_API_KEY=YOUR_API_KEY

Or, You can set environment variable by exporting your API key in your shell’s configuration file (e.g., .bashrc, .zshrc, or .profile)

If you don’t configure the API key, you will be prompted for your key when you first run the Shell GPT, which will then be stored in ~/.config/shell_gpt/.sgptrc.

Run the help command:

sgpt --help

Note: This is not a free API key. You need to pay as you use. 

Step 4: Verify the installation of Shell GPT

Let’s see if the API key works.

sgpt --help

Your terminal is now ready to answer anything. Your Shall GPT is ready to answer your queries, generate and execute commands, scripts, exploits, describe the given command or scripts. Anything you ask to do.

Different Modes of Shell GPT

Before you jump into the terminal. I want you to learn about the different modes of Shell GPT. You should know all these modes to get the better result.

  1. Shell Mode ( –shell): This mode allows generating shell commands.

  2. Code Mode ( –code): This mode is used to generates code scripts.

  3. Conversation Mode ( –chat): This opens an interactive prompt where queries can be asked and it provides detailed answers, just like a conversation.

  4. RPL Mode ( –repl): Stands for Read–Print–Loop mode.

  5. Describe Mode ( -d): This mode describe the given command or script.

Examples for –shell mode

Example for –d mode (Describe mod)

Examples for –code mode

Example for REPL mode

Shell GPT is an AI-powered command line productivity tool that aims to make using the terminal easier and more efficient. Remembering obscure commands and flags is one of the hardest parts of using the terminal. Shell GPT eliminates this issue by allowing users to generate specialized commands tailored to their needs with simple descriptive queries. It even describes what the commands do, saving users trips to documentation.

Crafting complex one-liner commands, scripts, and code via the terminal is time-consuming. Shell GPT writes these automatically based on what the user wants to accomplish. For example, it can generate full exploits, tools, and scripts by just outlining the objectives.

If you have this tool integrated on your machine or servers, you can confidently use commands on remote CLI terminals. Basically, this tool works as Microsoft co-pilot on the terminal.

We hope this guide helped you learn how to integrate your terminal with AI and reap the maximum output. Thanks for reading this post. Please share this post and help secure the digital world. Visit our website, thesecmaster.com, and our social media page on FacebookLinkedInTwitterTelegramTumblrMedium, and Instagram and subscribe to receive updates like this.  

You may also like these articles:

Arun KL

Arun KL is a cybersecurity professional with 15+ years of experience in IT infrastructure, cloud security, vulnerability management, Penetration Testing, security operations, and incident response. He is adept at designing and implementing robust security solutions to safeguard systems and data. Arun holds multiple industry certifications including CCNA, CCNA Security, RHCE, CEH, and AWS Security.

Recently added

Learn More About Cyber Security Security & Technology

“Knowledge Arsenal: Empowering Your Security Journey through Continuous Learning”

Cybersecurity All-in-One For Dummies - 1st Edition

"Cybersecurity All-in-One For Dummies" offers a comprehensive guide to securing personal and business digital assets from cyber threats, with actionable insights from industry experts.

Tools

Featured

View All

Learn Something New with Free Email subscription

Subscribe

Subscribe