linux ssh 服务器架设
1. 先看本机有没有安装openssh
#rpm -qa|grep openssh
如果有如上字样所示,则说明openssh已经安装了
2. 看看本机有没有安装openssl(openssl是openssh依赖的中间件)
#rpm -qa|grep openssl
如果有如上字样所示,则说明openssl已经安装了
3. 开启sshd 服务
#/etc/rc.d/init.d/sshd start
4. 查看sshd 服务进程端口(默认是22)
#netstat -an|grep :22
5. 修改ssh服务器的配置文件
#vim /etc/ssh/sshd_config
sshd_config配置文件一般保存默认就行了,可能有时需要一些个性配置
6. 生成公-密钥对
运行 ssh-keygen –t rsa命令如下:(不用管中间出现的东东,直接按enter就行)
ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): -----按回车
Enter passphrase (empty for no passphrase): -----按回车
Enter same passphrase again: -----按回车
Your identification has been saved in /root/.ssh/id_rsa. ------私钥
Your public key has been saved in /root/.ssh/id_rsa.pub. ------公钥
The key fingerprint is:
4d:eb:b0:21:d6:b3:de:c2:0e:16:93:dc:7d:df:13:9c root@192.168.1.10
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): -----按回车
Enter passphrase (empty for no passphrase): -----按回车
Enter same passphrase again: -----按回车
Your identification has been saved in /root/.ssh/id_rsa. ------私钥
Your public key has been saved in /root/.ssh/id_rsa.pub. ------公钥
The key fingerprint is:
4d:eb:b0:21:d6:b3:de:c2:0e:16:93:dc:7d:df:13:9c root@192.168.1.10
接着将id_rsa.pub(公钥) 拷到SSH服务器的/home/登陆用户名/.ssh/目录下(eg: /home/www/.ssh/)
运行命令:cat id_rsa.pub >> authorized_keys (将公钥id_rsa.pub内容追加到authorized_keys末尾)
7. 大功告成,可能还有些小细节后续再补上。