|
From: | Fernando Mercês |
Subject: | Re: [shell-script] Shell usando ssh com chave privada embebida no script |
Date: | Thu, 30 Oct 2014 16:56:21 -0200 |
Bom dia,Com a dica tentei das seguintes maneiras, seguem os debugs também.ssh -v -i <(cat /dev/stdin <<EOF
-----BEGIN RSA PRIVATE KEY-----
-----END RSA PRIVATE KEY-----
EOF) -T -p22 -l someuser 111.222.333.444 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
+ ssh -v -i /dev/fd/63 -T -p22 -l someuser 111.222.333.444 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
++ /dev/stdin
lixonew: line 2: /dev/stdin: Permission denied
OpenSSH_6.2p2, OpenSSL 1.0.1e-fips 11 Feb 2013
Warning: Identity file /dev/fd/63 not accessible: No such file or directory.
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 50: Applying options for *
debug1: Connecting to somehost.somedomain.tdl [111.222.3333.444] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1.4
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1.4 pat OpenSSH_5*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Warning: Permanently added 'somehost.somedomain.tdl111.222.3333.444' (ECDSA) to the list of known hosts.
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: No more authentication methods to try.
Permission denied (publickey).Esse foi o outro teste.#!/bin/bash
ssh -v -i < /dev/stdin -T -p22 -l someuser 111.222.333.444 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no <<EOF
-----BEGIN RSA PRIVATE KEY-----
-----END RSA PRIVATE KEY-----
EOF+ ssh -v -i -T -p22 -l someuser somehost.somedomain.tdl -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no
OpenSSH_6.2p2, OpenSSL 1.0.1e-fips 11 Feb 2013
Warning: Identity file -T not accessible: No such file or directory.
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 50: Applying options for *
Pseudo-terminal will not be allocated because stdin is not a terminal.
debug1: Connecting to somehost.somedomain.tdl [111.222.333.444] port 22.
debug1: Connection established.
debug1: identity file /home/someuser/.ssh/id_rsa type -1
debug1: identity file /home/someuser/.ssh/id_rsa-cert type -1
debug1: identity file /home/someuser/.ssh/id_dsa type 2
debug1: identity file /home/someuser/.ssh/id_dsa-cert type -1
debug1: identity file /home/someuser/.ssh/id_ecdsa type -1
debug1: identity file /home/someuser/.ssh/id_ecdsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1.4
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1.4 pat OpenSSH_5*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Warning: Permanently added 'somehost.somedomain.tdl,111.222.333..444' (ECDSA) to the list of known hosts.
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering DSA public key: /home/someuser/.ssh/id_dsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/someuser/.ssh/id_rsa
debug1: Trying private key: /home/someuser/.ssh/id_ecdsa
debug1: No more authentication methods to try.
Permission denied (publickey).Em Quarta-feira, 29 de Outubro de 2014 17:48, "Fredi Rolf Bieging address@hidden [shell-script]" <address@hidden> escreveu:
Tenta assim:
ssh -i <(comando_que_escreve_a_chave_no_stdout)2014-10-29 17:15 GMT-02:00 felipe diefenbach address@hidden [shell-script] <address@hidden>:Boa tarde lista.
Estou tentando fazer uma ferramenta para automatizar a conexão através do ssh.
Já estou usando chaves pub/priv corretamente.
Porém me deparei com um problema.
Ao criar o shell script de conexão preciso usar o comando ssh que usa a opção -i para receber um arquivo de chave (like ec2 aws).
Infelizmente o comando só suporta no parâmetro -i como entrada um arquivo. E eu não poderia disponibilizar em disco o arquivo de chave privada descriptografado.
A ideia inicial era criar um shell e compilá-lo, já com a chave embebida dentro do script, mas devido a estas limitações do comando ssh parece que terei que tomar outros caminhos.
Vasculhando na internet no site do ssh existe uma discussão a respeito do assunto, onde um camarada havia feito uma modificação no código c do ssh para aceitar como opção a chave privada através de uma variável ao invés de um arquivo. De qualquer forma não consegui encontrar os patchs para fazer o mesmo.
Cheguei o mais próximo dos resultados que busco com o seguinte código:
#!/bin/bash
ssh -i /dev/stdin -n -T -p 22 -l someuser 111.222.333.444 <<EOF
-----BEGIN RSA PRIVATE KEY-----
......
-----END RSA PRIVATE KEY-----
EOF
Mas o problema com este código é que ele faz a conexão e em seguida desconecta, como se eu estivesse concatenando um comando ao fim do comando ssh.
Tentei algumas outras formas de criptografia com o ccrypt e o gpg. Porem todos gerão um arquivo novo com a chave descriptografada. Permitindo que em algum momento qualquer um possa ler a chave privada.
Não tenho muita habilidade em lidar com o stdin e o stdout, por isso estou solicitando ajuda a lista. Talvez exista uma maneira de manter a conexão após efetuar o comando.
[Prev in Thread] Current Thread [Next in Thread]
- Shell usando ssh com chave privada embebida no script, felipe diefenbach, 2014/10/29
- Re: [shell-script] Shell usando ssh com chave privada embebida no script, Fredi Rolf Bieging, 2014/10/29
- Re: [shell-script] Shell usando ssh com chave privada embebida no script, felipe diefenbach, 2014/10/30
- Re: [shell-script] Shell usando ssh com chave privada embebida no script, Fernando Mercês <=
- Prev by Date: Procurar conteúdo de um array em outro.
- Next by Date: Re: Procurar conteúdo de um array em outro.
- Previous by thread: Re: [shell-script] Shell usando ssh com chave privada embebida no script
- Next by thread: Filtrar e concatenar linhas
- Index(es):