A versão originalmente instalada com o RedHat / CentOS 5.3 é a 4.3p2, e é meio antiga. A nova versão 5.2p1 possui várias novas funcionalidades, mas a melhor é a possibilidade de restringir o HOME do usuário para um diretório específico, ou seja, fazer um chroot, assim sendo, com o chroot implementado é possível liberar acesso SSH a um usuário sem que ele tenha acesso ao Sistema inteiro.
Posts relacionados
Instalar componentes necessários para compilação do OpenSSH
yum install gcc make automake bison autoconf libtool zlib-devel pam-devel libselinux-devel openssl-devel
Baixar o OpenSSH
wget ftp://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-5.2p1.tar.gz
Descompactar
tar zxvf openssh-5.2.tar.gz -C /usr/src cd /usr/src/openssh-5.2p1
Compilar e instalar
./configure --sysconfdir=/etc/openssh --with-pam --with-selinux --with-md5-passwords gmake gmake install
Ao final do processo de instalação, se tudo correr bem, serão geradas as chaves públicas e privadas.
Generating public/private rsa1 key pair. Your identification has been saved in /etc/openssh/ssh_host_key. Your public key has been saved in /etc/openssh/ssh_host_key.pub. The key fingerprint is: ba:eb:9e:21:24:4e:f8:be:f5:1f:14:b2:48:e8:aa:aeomain The key's randomart image is: +--[RSA1 2048]----+ | | | . | | . . . . | | o . . o . | |. + o . S | | = o o | |. o o o . | |.. . o + . | |E.o. oBo. | +-----------------+ Generating public/private dsa key pair. Your identification has been saved in /etc/openssh/ssh_host_dsa_key. Your public key has been saved in /etc/openssh/ssh_host_dsa_key.pub. The key fingerprint is: c0:ea:e1:05:43:16:43:a1:57:12:30:32:49:ab:4f:01omain The key's randomart image is: +--[ DSA 1024]----+ |EoooX+. | |.+.= = | | .o + o | |. o + . | |. . o . S | | o o o | | . o | | | | | +-----------------+ Generating public/private rsa key pair. Your identification has been saved in /etc/openssh/ssh_host_rsa_key. Your public key has been saved in /etc/openssh/ssh_host_rsa_key.pub. The key fingerprint is: 2e:ac:9b:a4:f2:22:ba:12:50:14:a4:64:9d:a6:8e:46omain The key's randomart image is: +--[ RSA 2048]----+ | ==.. | |o..+ | |..o | |.E | |= S | |oo . . | |.. . o . | |= o o . | |*=o +. | +-----------------+
Verificando a versão instalada
/usr/local/bin/ssh -V
OpenSSH_5.2p1, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
Configurando o OpenSSH para iniciar no boot e substituir a versão original
cd /etc/init.d cp sshd sshd.orig
Editar o arquivo /etc/init.d/sshd para que o início fique parecido com o seguinte, de acordo com a nova realidade
#!/bin/bash # # Init file for OpenSSH server daemon # # chkconfig: 2345 55 25 # description: OpenSSH server daemon # # processname: sshd # config: /etc/openssh/ssh_host_key # config: /etc/openssh/ssh_host_key.pub # config: /etc/openssh/ssh_random_seed # config: /etc/openssh/sshd_config # pidfile: /var/run/sshd.pid # source function library . /etc/rc.d/init.d/functions # pull in sysconfig settings [ -f /etc/sysconfig/sshd ] && . /etc/sysconfig/sshd RETVAL=0 prog="sshd" # Some functions to make the below more readable KEYGEN=/usr/local/bin/ssh-keygen SSHD=/usr/local/sbin/sshd RSA1_KEY=/etc/openssh/ssh_host_key RSA_KEY=/etc/openssh/ssh_host_rsa_key DSA_KEY=/etc/openssh/ssh_host_dsa_key PID_FILE=/var/run/sshd.pid ...
O que basicamente foi feito foi alterar os caminhos para os arquivos.
Erro ao conectar no SSHd após sua instalação
Após a atualização do OpenSSH e reiniciar o serviço, ao tentar conectar novamente no servidor a seguinte mensagem será apresentada:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the-middle attack)! It is also possible that the RSA host key has just been changed. The fingerprint for the RSA key sent by the remote host is 2e:ac:9b:a4:f2:22:ba:12:50:14:a4:64:9d:a6:8e:46. Please contact your system administrator. Add correct host key in /Users/daniel/.ssh/known_hosts to get rid of this message. Offending key in /Users/daniel/.ssh/known_hosts:33 RSA host key for 192.168.99.131 has changed and you have requested strict checking. Host key verification failed.
Isso acontece por que foram geradas novas chaves para o host.
Resolver isso é simples, basta editar o arquivo ~/.ssh/known_hosts e ir até a linha que é referente ao host, que é mostrada pela linha
Offending key in /Users/daniel/.ssh/known_hosts:33
ou seja, a chave do host está na linha 33 do arquivo knows_hosts. Editar o arquivo e ir até a linha 33 e apagá-la. Salve o arquivo.
Ao tentar conectar no servidor novamente:
ssh -l root 192.168.99.131
The authenticity of host '192.168.99.131 (192.168.99.131)' can't be established. RSA key fingerprint is 2e:ac:9b:a4:f2:22:ba:12:50:14:a4:64:9d:a6:8e:46. Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.99.131' (RSA) to the list of known hosts.
Para confirmar que o SSHd novo é o que está rodando, execute o comando
ps awx |grep sshd
10520 ? Ss 0:00 /usr/local/sbin/sshd 10579 ? Ss 0:00 sshd: root@pts/0
repare na linha referente onde está o novo binário /usr/local/sbin/sshd, isto confirma que o novo SSHd está sendo executado.

5 comments
Join the conversationJoão B. Silva - 06/09/2009
Muito bom o post. Mas teria como você publicar o .rpm do OpenSSH? Eu não queria ter que compilar ele em todos os meus hosts e com o .rpm eu instalaria em todos sem esforço.
Obrigado e continue com o bom trabalho.
Daniel K. - 06/09/2009
Claro! Já estou trabalhando nisso e disponibilizarei o .rpm do OpenSSH 5.2p1 para RedHat e CentOS.
Obrigado por comentar.
Daniel K. - 06/09/2009
Oi João, criei os pacotes RPM do OpenSSH pra poderem ser instalados sem maior esforço.
O post para o assunto está aqui http://www.fogonacaixadagua.com.br/2009/09/pacote-rpm-do-openssh-5-2p1/
Obrigado pela sugestão.
Pingback: Anonymous
Klau - 22/08/2011
This is a nice article. I´ve encountered this post several times this week searching for something alike. Now is in my mail box :) Keep up the great work!