This application sets up an SSH server that interacts with users via command line, leveraging OpenAI's GPT model to assist with Linux-related tasks. The assistant provides clear, concise, and accurate guidance for various Linux commands and issues.
- SSH Server: Users can connect to the server using SSH.
- GPT-3.5-turbo Integration: Commands are processed and responses are generated by the GPT-3.5-turbo model.
- Command History: Maintains a history of commands and responses for context.
- Python 3.6+
paramiko
libraryopenai
library- OpenAI API key
- SSH server key
-
Install Dependencies:
pip install paramiko openai
-
Obtain an OpenAI API Key:
Sign up on the OpenAI website to get your API key.
-
Set Up Environment Variables:
Set the OpenAI API key as an environment variable:
export OPENAI_API_KEY='your_openai_api_key'
-
Generate SSH Server Key:
If you don't already have an SSH server key, generate one:
ssh-keygen -t rsa -b 4096 -f ssh_host_rsa_key
-
Run the Server:
python3 main.py
-
Start the Server:
The server will start listening for connections on port 22.
[+] Listening for connection ...
-
Connect via SSH:
Use an SSH client to connect to the server:
ssh user@your_server_ip
-
Interact with the Assistant:
Once connected, type your Linux commands. The assistant will provide detailed responses.
$ ls -l
The assistant will respond with helpful information regarding the
ls -l
command. -
Exit the Session:
Type
exit
to end the session.$ exit
- handle_command_with_gpt(command): Sends user commands to the GPT-3.5-turbo model and returns the response.
- Server(paramiko.ServerInterface): Implements the SSH server interface, handling authentication and shell requests.
- start_server(): Starts the SSH server and handles client connections.
The function handle_command_with_gpt(command)
:
- Appends the command to the command history.
- Prepares the prompt with system and user messages.
- Calls the OpenAI API to get a response.
- Appends the response to the command history.
- Returns the response.
The Server
class and start_server()
function:
- Initialize the SSH server and listen for connections.
- Authenticate users and set up an interactive shell.
- Read user commands, process them using GPT-3.5-turbo, and send responses back to the client.
- Authentication: Currently, the server is set to accept any username and password. This should be updated with proper authentication mechanisms for production use.
- Port Configuration: Ensure the server runs on a non-default port in production to avoid conflicts and potential security issues.
- Implement stronger authentication methods.
- Add logging and monitoring for the server.
- Enhance error handling and robustness.
- Provide configuration options for port and other settings.
This project is licensed under the MIT License.