shellhub-io / shellhub

:computer: Get seamless remote access to any Linux device. Centralized SSH for the edge and cloud computing
https://shellhub.io
Apache License 2.0
1.39k stars 139 forks source link

Can't add a private ssh key #3549

Closed tobagin closed 8 months ago

tobagin commented 8 months ago

Description

I'm not able to add a private ssh key. it doesn't matter the type of key I try adding it always give me the same error: Not is a valid private key I've attached bellow a screenshot of a sample key I generated using the following command: ssh-keygen -t rsa -b 4096 -f ~/.ssh/sample.key -C "My web-server key" and a screenshot of the shellhub upon adding the key to it.

Screenshot from 2024-02-18 19-42-03 Screenshot from 2024-02-18 19-58-25

Edition

Community

Version

latest (docker)

heiytor commented 8 months ago

Hi, @tobagin.

I've spent some time trying to reproduce this, and the only way I managed to do so was by removing certain characters, such as:

Could you confirm whether you copied and pasted the key with all of its characters intact?

If it still doesn't work, could you please generate a new private key that doesn't work and send it here?

tobagin commented 8 months ago

same thing happen with a new key, I've tried rsa, dsa and ed25519, all with the same result.

Screenshot from 2024-02-19 20-34-00 Screenshot from 2024-02-19 20-34-06 Screenshot from 2024-02-19 20-34-55 Screenshot from 2024-02-19 20-39-03

-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHIAAAAGYmNyeXB0AAAAGAAAABB0cPlujN
8ORg9YX9cHvHrtAAAAEAAAAAEAAAIXAAAAB3NzaC1yc2EAAAADAQABAAACAQCkgcnYvoWH
6pEDX2c5YJ7k0stZyL0fp6Kzu9QoNFcV+aMnmF+meoBlAab6Kae2SuKI3zfkHDMIfKBk6T
qPOoQgmLLPHAlf1+xocw5xlyJTIU4WyLeUomdZbVGofL4gSAVm2Wt8yVAK+rEYEhlijufh
g2BsPk6b/dxWZ88SLCxCFE1Db2FoA2eqKkjsoRQo3pOYaaT0j1igfsJteQkOpr/rkhYCzR
bqrJ/44fifuUESkCNi0Clb5yp/5JNMevxIbaBx1/MDCFZiT+z+w4ihmLamI2rompA8hat9
oHuMmwMl1YPKbXOvaC5uxGDff7OItOOL88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43YpWNELCrDmghh+5DiHOPB16
lWrVEbPOEY2pR0ZzScZ7IUG7lk54lhf2KoPOXJjm70Rnzm2II/NVaDKiZL6z1peNxERMmA
faoC5glOBCV1wkePcheStqFUL1KUDbKEJzLLrFX+aIRXIugXrLoOY9wXdOd/A9ZndQsh1B
ze/wWTF52RSBsduaZCj1RC6kw8wKLkFXR3QNhuzqGcd23k8uKGJjO3d1SKMFHpDfkZWBw2
ECKvDK9lhbVPw2SJjTdvUm5FXB5zYn953S1HNGo9SnGdi4R5KCztaWzfk7/JrcjJYdjCa6
oFlvEZtf2H3RquRHK5gdisMEC9Wmii4r/unOjvHA4s3uC2ESCevrt+IJvPMNpwuKCffoFf
CrnNJ4FHjiy6zJwGcpDFlIckVwA6Kh9GwkuYV1hhf/eAYVdNkm/DhhH/SBpoWomYGkTFny
LynCfHUeh2fMekmQ84IMrSq7ntmLg/QN8aZ4YItejooQPQMfa+AaePIVQQtr+1ejigtDkP
8sHq4zkk3fiw61oh+Pz1h1Tfs96GI0+WEd/q0uh5mREzH19bOOslY5zEfINCa2sLOZaZ79
hDSwIg5A3zcXPWSMHzEhMaRU3N/s4E54VXq1sfVpq1mvkSLoSqjhR2ZFo+7BaASoBAgPWc
v+A8F5GBwc1QQyNSVrm5gwtESICr5WX0gRhZldXN5chEa23B0VtVHr+MR52Dd8BCh9DXwL
3OTzPt3CdkRO59B+FT6hFJikA=
-----END OPENSSH PRIVATE KEY-----

here is the docker-compose.yml of my deployment in case something is wrong here. I'm deploying with the tag 'latest'.

version: "3.7"
services:
  ssh:
    image: shellhubio/ssh:${SHELLHUB_VERSION}
    container_name: shellhub-ssh
    restart: unless-stopped
    environment:
      - PRIVATE_KEY=/run/secrets/ssh_private_key
      - SHELLHUB_ENTERPRISE=${SHELLHUB_ENTERPRISE}
      - SHELLHUB_CLOUD=${SHELLHUB_CLOUD}
      - SHELLHUB_LOG_LEVEL=${SHELLHUB_LOG_LEVEL}
      - SHELLHUB_BILLING=${SHELLHUB_BILLING}
      - ALLOW_PUBLIC_KEY_ACCESS_BELLOW_0_6_0=${SHELLHUB_ALLOW_PUBLIC_KEY_ACCESS_BELLOW_0_6_0}
      - RECORD_URL=${SHELLHUB_RECORD_URL}
      - BILLING_URL=${SHELLHUB_BILLING_URL}
    ports:
      - "${SHELLHUB_SSH_PORT}:2222"
    secrets:
      - ssh_private_key
    networks:
      - frontend
    healthcheck:
      test: "curl -f http://ssh:8080/healthcheck || exit 1"
      interval: 30s
      start_period: 10s

  api:
    image: shellhubio/api:${SHELLHUB_VERSION}
    container_name: shellhub-api
    restart: unless-stopped
    environment:
      - SHELLHUB_VERSION=${SHELLHUB_VERSION}
      - PRIVATE_KEY=/run/secrets/api_private_key
      - PUBLIC_KEY=/run/secrets/api_public_key
      - SHELLHUB_ENTERPRISE=${SHELLHUB_ENTERPRISE}
      - SHELLHUB_BILLING=${SHELLHUB_BILLING}
      - SHELLHUB_CLOUD=${SHELLHUB_CLOUD}
      - GEOIP=${SHELLHUB_GEOIP}
      - MAXMIND_LICENSE=${SHELLHUB_MAXMIND_LICENSE}
      - RECORD_RETENTION=${SHELLHUB_RECORD_RETENTION}
      - TELEMETRY=${SHELLHUB_TELEMETRY}
      - TELEMETRY_SCHEDULE=${SHELLHUB_TELEMETRY_SCHEDULE}
      - SESSION_RECORD_CLEANUP_SCHEDULE=${SHELLHUB_SESSION_RECORD_CLEANUP_SCHEDULE}
      - SHELLHUB_LOG_LEVEL=${SHELLHUB_LOG_LEVEL}
      - SENTRY_DSN=${SHELLHUB_SENTRY_DSN}
      - SHELLLHUB_ANNOUNCEMENTS=${SHELLLHUB_ANNOUNCEMENTS}
      - SHELLHUB_SSH_PORT=${SHELLHUB_SSH_PORT}
      - SHELLHUB_DOMAIN=${SHELLHUB_DOMAIN}
      - ASYNQ_GROUP_MAX_DELAY=${SHELLHUB_ASYNQ_GROUP_MAX_DELAY}
      - ASYNQ_GROUP_GRACE_PERIOD=${SHELLHUB_ASNYQ_GROUP_GRACE_PERIOD}
      - ASYNQ_GROUP_MAX_SIZE=${SHELLHUB_ASYNQ_GROUP_MAX_SIZE}
    depends_on:
      - mongo
    links:
      - mongo
    secrets:
      - api_private_key
      - api_public_key
    networks:
      - frontend
    healthcheck:
      test: "curl -f http://api:8080/api/healthcheck || exit 1"
      interval: 30s
      start_period: 10s

  ui:
    image: shellhubio/ui:${SHELLHUB_VERSION}
    container_name: shellhub-ui
    restart: unless-stopped
    environment:
      - SHELLHUB_STRIPE_PUBLISHABLE_KEY=${STRIPE_PUBLISHABLE_KEY}
      - SHELLHUB_BILLING=${SHELLHUB_BILLING}
      - SHELLHUB_ENTERPRISE=${SHELLHUB_ENTERPRISE}
      - SHELLHUB_CLOUD=${SHELLHUB_CLOUD}
      - SHELLHUB_ANNOUNCEMENTS=${SHELLHUB_ANNOUNCEMENTS}
      - SHELLHUB_VERSION=${SHELLHUB_VERSION}
      - SHELLHUB_SENTRY_DSN=${SHELLHUB_SENTRY_DSN}
    networks:
      - frontend

  gateway:
    image: shellhubio/gateway:${SHELLHUB_VERSION}
    container_name: shellhub-gateway
    restart: unless-stopped
    environment:
      - SHELLHUB_DOMAIN=${SHELLHUB_DOMAIN}
      - SHELLHUB_PUBLIC_URL_DOMAIN=${SHELLHUB_PUBLIC_URL_DOMAIN}
      - SHELLHUB_VERSION=${SHELLHUB_VERSION}
      - SHELLHUB_SSH_PORT=${SHELLHUB_SSH_PORT}
      - SHELLHUB_PROXY=${SHELLHUB_PROXY}
      - SHELLHUB_ENTERPRISE=${SHELLHUB_ENTERPRISE}
      - SHELLHUB_CLOUD=${SHELLHUB_CLOUD}
      - SHELLHUB_AUTO_SSL=${SHELLHUB_AUTO_SSL}
    depends_on:
      - api
      - ui
    ports:
      - ${SHELLHUB_HTTP_PORT}:80
    volumes:
      - shellhub-gateway:/etc/letsencrypt
    networks:
      - frontend

  cli:
    image: shellhubio/cli:${SHELLHUB_VERSION}
    container_name: shellhub-cli
    entrypoint: /bin/sleep infinity
    restart: unless-stopped
    environment:
      - SHELLHUB_LOG_LEVEL=${SHELLHUB_LOG_LEVEL}
    depends_on:
      - api
      - mongo
    networks:
      - frontend

  mongo:
    image: mongo:4.4.8
    container_name: shellhub-mongo
    restart: unless-stopped
    healthcheck:
      test: 'test $$(echo "rs.initiate({ _id: ''rs'', members: [ { _id: 0, host: ''mongo:27017'' } ] }).ok || rs.status().ok" | mongo --quiet) -eq 1'
      interval: 30s
      start_period: 10s
    command: ["--replSet", "rs", "--bind_ip_all"]
    volumes:
      - shellhub-mongo:/data/configdb
      - shellhub-db:/data/db
    networks:
      - frontend

  redis:
    image: redis:latest
    container_name: shellhub-redis
    restart: unless-stopped
    volumes:
      - shellhub-redis:/data
    networks:
      - frontend

secrets:
  ssh_private_key:
    file: /opt/ssh_private_key
  api_private_key:
    file: /opt/api_private_key
  api_public_key:
    file: /opt/api_public_key

networks:
  frontend:
    external: true

volumes:
  shellhub-db:
    external: true
  shellhub-gateway:
    external: true
  shellhub-mongo:
    external: true
  shellhub-redis:
    external: true
tobagin commented 8 months ago

after some investigation here I found that every single key I created using ssh-keygen for some reason is not accepted when I insert into shellhub. I've created a new key using openssl genrsa -out sample.key 2048 and than generated the public with openssl rsa -in sample.key -out sample.key.pub -pubout, and it worked.

I found the problem, it seems that shellhub is not accepting keys with passphrase. I've generated a new key using ssh-keygen without passphrase and it accepted.