centos 下启用sshd服务

centos 下启用sshd服务 
ssh localhost
错误信息为:ssh: connect to host localhost port 22: Connection refused
这种错误很主要的一个原因是sshd服务没有启动,先启动sshd服务后就没有问题了

1、查卡服务是否启用
ps -ef | grep ssh

2、如果没有启用 则要安装
yum install openssh-server

3、安装完之后开启
/etc/init.d/sshd start
如果/etc/init.d/sshd start出现:
Generating SSH1 RSA host key:                              [FAILED]
解决办法:
$ yum search openssh
$ sudo yum install openssh
如果已经安装openssh,启动sshd
$ sudo /etc/init.d/sshd start
sshd re-exec requires execution with an absolute path
[honki@localhost ~]$ sudo service sshd start
Generating SSH1 RSA host key:                              [  OK  ]
Generating SSH2 RSA host key:                              [  OK  ]
Generating SSH2 DSA host key:                              [  OK  ]
Starting sshd:                                             [  OK  ]

4、如果还是连不上 关闭防火墙
/etc/init.d/iptables stop

如此即可。


ssh localhost 免登录:

[bigdata@localhost ~]$ mkdir .ssh
[bigdata@localhost ~]$ chmod 700 .ssh
[bigdata@localhost ~]$ cd .ssh/     
[bigdata@localhost .ssh]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
一路回车    
Enter file in which to save the key (/home/bigdata/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):                     
Enter same passphrase again:
Your identification has been saved in /home/bigdata/.ssh/id_rsa.
Your public key has been saved in /home/bigdata/.ssh/id_rsa.pub.
The key fingerprint is:
51:c6:8b:54:45:09:cf:47:c0:89:0a:80:44:73:2e:df [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
| o+.o.   o=*++.  |
|  .+  . .ooo+.   |
|  . .  o.o .o .  |
|   o .  o..  .   |
|    . E S        |
|                 |
|                 |
|                 |
|                 |
+-----------------+
[bigdata@localhost .ssh]$ ls -l
total 8
-rw-------. 1 bigdata bigdata 1675 Jan 24 15:54 id_rsa
-rw-r--r--. 1 bigdata bigdata  411 Jan 24 15:54 id_rsa.pub
[bigdata@localhost .ssh]$ cp id_rsa.pub authorized_keys
[bigdata@localhost .ssh]$ chmod 644  authorized_keys
[bigdata@localhost ~]$ ssh localhost
Last login: Thu Jan 24 15:55:14 2013 from localhost.localdomain

$vi /etc/ssh/sshd_config
RSAAuthentication yes # 启用 RSA 认证
PubkeyAuthentication yes # 启用公钥私钥配对认证方式
AuthorizedKeysFile .ssh/authorized_keys # 公钥文件路径(和上面生成的文件同)

service sshd restart

猜你喜欢

转载自honkideng.iteye.com/blog/1774774