ocli-ssh

command module
v0.0.0-...-d0d53dd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2025 License: MIT Imports: 29 Imported by: 0

README

OCLI SSH Server

A multi-user SSH server for OCLI that allows users to access their personal OCLI instances remotely via SSH.

Features

  • Multi-user support: Each user has isolated data storage
  • SSH key authentication: Secure access using SSH public keys
  • Auto-registration: New users created automatically on first connection
  • Persistent storage: User data is automatically saved
  • Full OCLI functionality: All OCLI features available over SSH
  • Easy user management: Simple commands to add/remove users

Quick Start

For Users (Connecting to OCLI)

Option 1: Install OCLI client (Recommended)

curl -fsSL https://raw.githubusercontent.com/vladzima/ocli/main/cmd/ocli-ssh/install-client.sh | bash
ocli  # Connect instantly!

Option 2: Setup SSH config

curl -fsSL https://raw.githubusercontent.com/vladzima/ocli/main/cmd/ocli-ssh/setup-ssh-config.sh | bash
ssh ocli  # Connect with short command!

Option 3: Direct connection

ssh username@34.61.150.52 -p 2222
For Server Administrators
1. Build the Server
cd cmd/ocli-ssh
go build -o ocli-ssh .
2. Generate SSH Keys (for testing)

If you don't have SSH keys:

ssh-keygen -t ed25519 -f ~/.ssh/ocli_test_key -N ""
3. Start the Server

Basic usage:

sudo ./ocli-ssh

With auto-registration enabled:

./ocli-ssh --auto-register --host 0.0.0.0 --port 2222 --data-dir ./data

Auto-registration mode: Users are created automatically when they first connect with their SSH key.

4. Connect

With auto-registration (recommended):

ssh alice@localhost -p 2222 -i ~/.ssh/ocli_test_key

User alice will be created automatically on first connection.

Manual user creation:

./ocli-ssh --add-user alice:~/.ssh/ocli_test_key.pub
ssh alice@localhost -p 2222 -i ~/.ssh/ocli_test_key

Command Line Options

  • --host: Host to bind to (default: 0.0.0.0)
  • --port: Port to bind to (default: 2222)
  • --data-dir: Directory for user data (default: /var/lib/ocli-ssh)
  • --key: Path to SSH host key (auto-generates if not specified)
  • --auto-register: Enable auto-registration of new users (default: false)
  • --add-user: Add a user (format: username:path/to/public_key.pub)
  • --del-user: Remove a user

User Management

Adding Users
# Add a new user with their public key
./ocli-ssh --add-user alice:~/.ssh/alice_key.pub

# The user can now connect with:
ssh alice@your-server -p 2222 -i ~/.ssh/alice_key
Removing Users
# Remove a user and all their data
./ocli-ssh --del-user alice

Data Storage

User data is stored in:

<data-dir>/
├── users/
│   ├── alice/
│   │   ├── authorized_keys
│   │   └── data.json
│   └── bob/
│       ├── authorized_keys
│       └── data.json

Deployment

Systemd Service

Create /etc/systemd/system/ocli-ssh.service:

[Unit]
Description=OCLI SSH Server
After=network.target

[Service]
Type=simple
User=ocli
Group=ocli
WorkingDirectory=/opt/ocli-ssh
ExecStart=/opt/ocli-ssh/ocli-ssh --data-dir /var/lib/ocli-ssh
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

Then:

# Create user and directories
sudo useradd -r -s /bin/false ocli
sudo mkdir -p /opt/ocli-ssh /var/lib/ocli-ssh
sudo chown ocli:ocli /var/lib/ocli-ssh

# Copy binary
sudo cp ocli-ssh /opt/ocli-ssh/
sudo chown ocli:ocli /opt/ocli-ssh/ocli-ssh

# Start service
sudo systemctl daemon-reload
sudo systemctl enable ocli-ssh
sudo systemctl start ocli-ssh
Docker

Create a Dockerfile:

FROM golang:1.23-alpine AS builder
WORKDIR /app
COPY . .
RUN cd cmd/ocli-ssh && go build -o ocli-ssh .

FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /app/cmd/ocli-ssh/ocli-ssh .
EXPOSE 2222
CMD ["./ocli-ssh", "--data-dir", "/data"]

Build and run:

docker build -t ocli-ssh .
docker run -d -p 2222:2222 -v ocli-data:/data ocli-ssh

Security Considerations

  1. Host Key: The server generates a host key automatically if not specified. For production, use a persistent host key to avoid SSH warnings.

  2. File Permissions: Ensure the data directory has appropriate permissions (700 for user directories).

  3. Network Security: Consider using a firewall to restrict access to the SSH port.

  4. User Isolation: Each user's data is completely isolated from others.

Troubleshooting

Permission Denied

Ensure your SSH key permissions are correct:

chmod 600 ~/.ssh/your_private_key
Connection Refused

Check if the server is running and listening:

sudo netstat -tlnp | grep 2222
Authentication Failed

Verify the user was added correctly:

ls -la /var/lib/ocli-ssh/users/username/authorized_keys

Development

Testing Locally
# Terminal 1: Start server
go run . --data-dir ./test-data

# Terminal 2: Add test user
go run . --add-user test:~/.ssh/id_ed25519.pub

# Terminal 3: Connect
ssh test@localhost -p 2222
Contributing
  1. Fork the repository
  2. Create your feature branch
  3. Make your changes
  4. Submit a pull request

License

Same as OCLI - MIT License

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址