Skip to content

vpuhoff/chatgpt_over_ssh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chatgpt over SSH server assistant

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.

Features

  • 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.

Requirements

  • Python 3.6+
  • paramiko library
  • openai library
  • OpenAI API key
  • SSH server key

Setup

  1. Install Dependencies:

    pip install paramiko openai
  2. Obtain an OpenAI API Key:

    Sign up on the OpenAI website to get your API key.

  3. Set Up Environment Variables:

    Set the OpenAI API key as an environment variable:

    export OPENAI_API_KEY='your_openai_api_key'
  4. 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
  5. Run the Server:

    python3 main.py

Usage

  1. Start the Server:

    The server will start listening for connections on port 22.

    [+] Listening for connection ...
  2. Connect via SSH:

    Use an SSH client to connect to the server:

    ssh user@your_server_ip
  3. 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.

  4. Exit the Session:

    Type exit to end the session.

    $ exit

Code Overview

Main Components

  • 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.

Command Handling

The function handle_command_with_gpt(command):

  1. Appends the command to the command history.
  2. Prepares the prompt with system and user messages.
  3. Calls the OpenAI API to get a response.
  4. Appends the response to the command history.
  5. Returns the response.

SSH Server

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.

Security Considerations

  • 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.

Future Improvements

  • Implement stronger authentication methods.
  • Add logging and monitoring for the server.
  • Enhance error handling and robustness.
  • Provide configuration options for port and other settings.

License

This project is licensed under the MIT License.


About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published