1.查询有没有安装ssh
[root@localhost .ssh]# rpm -q openssh-clients openssh-clients-5.3p1-70.el6.i686 [root@localhost .ssh]# rpm -q openssh-server openssh-server-5.3p1-70.el6.i686
2.生成密钥公钥,私钥
[root@localhost .ssh]# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): OK_rsa #是不是默认都有/root/.ssh/id_rsa目录下 Enter passphrase (empty for no passphrase): #输入密钥文件密码 Enter same passphrase again: Your identification has been saved in OK_rsa. Your public key has been saved in OK_rsa.pub. The key fingerprint is: 9e:b5:ae:96:1e:34:84:62:bc:c8:ec:e4:3b:31:f3:47 root@localhost The key's randomart p_w_picpath is: +--[ RSA 2048]----+ | | | . . | | + . . | | o o o . | | = . S . | | ++ Eo + . | | o= . +.. | | ... . oo | | .. . oo.. | +-----------------+ [root@localhost .ssh]# [root@localhost .ssh]# ls authorized_keys id_rsa id_rsa.pub OK_rsa OK.pub
#其中OK_rsa为私密
#OK.pub为公密
3. 将公钥重命名为authorized_keys ,copy到(/root/.ssh/id_rsa目录下)
私钥怎么使用,当然是copy到你自已的电脑上了,加载这个文件是需要密码的,就是生成密钥时你输入的密码,请勿忘记。
4.修改/etc/ssh/sshd_config ,重启sshd服务
PasswordAuthentication yes 改成 PasswordAuthentication no
修改sshd_config之前备份一下
[root@localhost .ssh]#cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
重启sshd服务
[root@localhost .ssh]# service sshd restart
5.补一下,机器环境
[root@localhost .ssh]# uname -a Linux localhost 2.6.32-220.el6.i686 #1 SMP Tue Dec 6 16:15:40 GMT 2011 i686 i686 i386 GNU/Linux
6.端口的修改
22 改成8888
修改/etc/ssh/sshd_config ,重启sshd服务
Port 22 改成8888
修改iptables
[root@localhost xjb]# vim /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
见到了么 22 改成8888就可以了
[root@localhost xjb]# service iptables restart
排错
在root目录下
排错,必需要有(/root/.ssh/id_rsa)目录,默认只有 /root/.ssh 目录, 需自己建id_rsa 目录
没有这个图案,rsa是不生成的
The key's randomart p_w_picpath is:
+--[ RSA 2048]----+
| |
| . . |
| + . . |
| o o o . |
| = . S . |
| ++ Eo + . |
| o= . +.. |
| ... . oo |
| .. . oo.. |
+-----------------+
转载于:https://blog.51cto.com/ablinuxer/1692281