Exploring ChatGPT's Magic in the Linux Command Line
Tags: chatgpt, openai, linux, automation
Published: 2023-09-07 14:52:28

Integrating ChatGPT into the Linux terminal opens a world of possibilities for natural language interactions and automation. By combining the power of OpenAI's ChatGPT with the flexibility of the Linux terminal, users can harness the capabilities of this language model for a wide range of tasks and applications.

**ShellGPT:**

Users can communicate with the AI chatbot on their Linux terminal using ShellGPT, a command line interface for ChatGPT. It is based on the GPT large language model from OpenAI.

Based on our text input, ShellGPT can provide intelligent suggestions and recommendations and even run shell commands. Additionally, it gains knowledge from our exchanges and improves with time. Users no longer need to input lengthy commands or memorize difficult Linux Terminal commands thanks to the ChatGPT application included into the command line. By having ChatGPT handle part of their tedious labor on their behalf, they may reduce errors while saving critical time.

Prerequisites to install ChatGPT in Linux:
1. AWS account
2. Create an EC2 Instance(Ubuntu).

Steps:

a. Create an EC2 instance and SSH into it.

![EC2Instance](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qzty3r3oej1vcgnb9z9y.png)

b. Check if Python is installed in it or not.

![check python version](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8pf6f7anatcv79zl58v4.png)

c. Install PIP and check the version.

![Install PIP](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/67kb5rc1h90q6ml2flpx.png)


![PIP Version](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i03hovj7dvrgwyj4csph.png)

d. Install venv.

![Install venv](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uw03fuvzxvrj0ac6ld68.png)

e. Setup ShellGPT to use ChatGPT.

 1. Setup environment.
 2. Create a directory.

![mkdir](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qfz01ii3236teb1mwp7w.png)

 3. Create a virtual environment.

![create virtual env](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o7oqghcnf5l0xm26mrl8.png)

 4. Activate the env.

![activate env](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sg3z09gcy0mbqp45qhw2.png)

f. To get OpenAI API Key, navigate to OpenAI’s website.

![OpenAi](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kh6pk5xbwba3h6h5t185.png)

g. Click on profile and select View API Keys.

![profile](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6hee6pr51x3k2a26lp8b.png)

h. Click on Create new Secret key.

![create key](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tnzux0p16cef2zs8v0sk.png)

i. Copy the Key and save it.

j. Now, create an environment variable for this API key with the command below. In Linux, you can create an environment variable using the “export” command.

Replace <your_OpenAI_API_key_here> placeholder with the actual API key you generated to use ChatGPT in the Linux terminal.

`export OPENAI_API_KEY=sk-YHhk0****************RMVLVZdqQjiNZ`


![export](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/of45wvol6jwi39lvug2q.png)

k. To verify if the export is successfully use env.

![verifyexport](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ji45g485e2djx0ol34h9.png)

l. To store variable permanently, open .bashrc file and add the API key.


![bashrc](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g0wofp4hkwbgdfnnznfp.png)

m. To make commands in effect, run the command: source .bashrc .

![commandeffect](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8p6o6tseqvmxgxqtheqo.png)

n. Install ShellGPT.


![InstallShellGPT](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vjy4yg9pkgy9s3098a3o.png)

o. Now that we have install ShellGPT, we can use it.


Syntax:

![chat Syntax](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eq9ci483658b9mn72ott.png)


| Options        | Description|
| ------------- |:-------------:|
| --temperature |Changes the randomness of the output | 
| --top-probablity|  Limits to only the highest probable tokens or words|
| --chat | Used to have a conversation with a unique name|
|--shell| Used to get shell commands as output|
|--execute|Executes the commands received as output from --shell option|
|--code|Used to get code as output|

In Action:

![OP1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lpfxu3g9k0v710c48uaw.png)


![OP2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uysqwjndm6cfqtfrkygy.png)

Let's [Connect!](https://beacons.ai/rahulsharma.rks)