Gerando remotamente par de chaves sem senha


2

Estou tentando gerar o par de chaves (sem uma senha) em uma máquina remota. O comando que eu uso para isso é:

ssh root@REMOTEIP ssh-keygen -t rsa -f /root/.ssh/id_rsa_new -q -N ""

A saída deste comando é:

ssh-keygen: option requires an argument -- N
Usage: ssh-keygen [options]
Options:
  -a trials   Number of trials for screening DH-GEX moduli.
  -B          Show bubblebabble digest of key file.
  -b bits     Number of bits in the key to create.
  -C comment  Provide new comment.
  -c          Change comment in private and public key files.
  -e          Convert OpenSSH to IETF SECSH key file.
  -F hostname Find hostname in known hosts file.
  -f filename Filename of the key file.
  -G file     Generate candidates for DH-GEX moduli.
  -g          Use generic DNS resource record format.
  -H          Hash names in known_hosts file.
  -i          Convert IETF SECSH to OpenSSH key file.
  -l          Show fingerprint of key file.
  -M memory   Amount of memory (MB) to use for generating DH-GEX moduli.
  -N phrase   Provide new passphrase.
  -P phrase   Provide old passphrase.
  -p          Change passphrase of private key file.
  -q          Quiet.
  -R hostname Remove host from known_hosts file.
  -r hostname Print DNS resource record.
  -S start    Start point (hex) for generating DH-GEX moduli.
  -T file     Screen candidates for DH-GEX moduli.
  -t type     Specify type of key to create.
  -v          Verbose.
  -W gen      Generator to use for generating DH-GEX moduli.
  -y          Read private key file and print public key.

Quando eu uso uma senha, o comando funciona perfeitamente:

ssh root@REMOTEIP ssh-keygen -t rsa -f /root/.ssh/id_rsa_new -q -N "12345"

Respostas:


1

Para evitar isso, é necessário citar o comando inteiro para evitar que ele seja dividido pelo shell local:

ssh root@REMOTEIP "ssh-keygen -t rsa -f /root/.ssh/id_rsa_new -q -N ''"

O problema é que ssh, com o objetivo de ser compatível com rsh(que foi substituído inicialmente), envia toda a linha de comando como um único argumento que é posteriormente transmitido ao shell remoto (no Unix $SHELL -c "your command").

  1. Quando você corre

    ssh root@REMOTEIP ssh-keygen -t rsa -f /root/.ssh/id_rsa_new -q -N ""

  2. o shell local executa

    ["ssh", "root@REMOTEIP", "ssh-keygen", "-t", "rsa", "-f", "/root/.ssh/id_rsa_new", "-q", "-N", ""]

  3. que sshconcatena para obter

    "ssh-keygen -t rsa -f /root/.ssh/id_rsa_new -q -N "

  4. e o shell remoto se divide novamente para

    ["ssh-keygen", "-t", "rsa", "-f", "/root/.ssh/id_rsa_new", "-q", "-N"]

    - observe os argumentos vazios ausentes.

Ao utilizar nosso site, você reconhece que leu e compreendeu nossa Política de Cookies e nossa Política de Privacidade.
Licensed under cc by-sa 3.0 with attribution required.