码迷,mamicode.com
首页 > 其他好文 > 详细

1.SSHD服务

时间:2017-09-01 10:53:17      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:待完善

1. SSHD服务

1SSH协议:安全外壳协议,为Secure Shell的缩写。SSH是建立在应用层和传输层基础上的安全协议,sshd服务使用ssh协议来进行远程控制和完成计算机之间的文件传送。传统的传输方式是telnet(终端仿真协议),这种方式极为不安全,并且会使用明文传输密码。

2OpenSSH软件包,提供了服务端后台程序和客户端工具,用来加密远程控件和文件传输过程中的数据,并由此来代替原来类似的服务。

OpenSSH服务需要的3个软件包:

[root@zhao1 ~]# rpm -qa | grep openssh#查看已安装的openssh相关软件包

openssh-5.3p1-84.1.el6.x86_64#包含openssh服务器及客户端的核心文件

openssh-askpass-5.3p1-84.1.el6.x86_64

openssh-clients-5.3p1-84.1.el6.x86_64#openssh客户端软件包

openssh-server-5.3p1-84.1.el6.x86_64#openssh服务器软件包

[root@zhao1 ~]# rpm -pqi /mnt/Packages/openssh-5.3p1-84.1.el6.x86_64.rpm #查看该软件包的作用

(3)OpenSSH配置文件

[root@zhao1 ~]# rpm -pql /mnt/Packages/openssh-server-5.3p1-84.1.el6.x86_64.rpm#查看该软件包所包含的配置文件

OpenSSH常用的配置文件是:/etc/ssh/sshd_config/etc/ssh/ssh_config,其中/etc/ssh/sshd_config为服务端配置文件,/etc/ssh/ssh_config为客户端配置文件。

服务端的配置文件:

[root@zhao1 ~]# vim /etc/ssh/sshd_config

 13 #Port 22#设置sshd监听端口号

SSH预设会使用22这个port,也可以使用多个port。例如,想要开放sshd端口为22222,此时可以多加一行Port 222即可,然后重启sshd就好了。

 15 #ListenAddress 0.0.0.0#设置sshd服务器绑定的IP地址,0.0.0.0表示监听所有地址

 21 Protocol 2#选择SSH的协议版本,如果想支持版本1,可以改为Protocol 21

 36 SyslogFacility AUTHPRIV#定义日志类别,默认日志在/var/log/secure文件中

查看系统各类日志存放地点:

[root@zhao1 ~]# vim /etc/rsyslog.conf

 41 #LoginGraceTime 2m#多长时间没有成功连上SSH就强迫断线

 42 #PermitRootLogin yes#是否允许root登录

 64 #PasswordAuthentication yes#密码验证

 65 #PermitEmptyPasswords no#是否允许空密码登录

112 #PrintMotd yes#登录后打印出登录时间、地点以及/etc/motd中的内容

116 #UsePrivilegeSeparation yes#是否允许权限较低的用户操作程序

122 #UseDNS yes

 80 #GSSAPIAuthentication no#此两项为使用DNS去反查客户端的主机名,来判断客户端的来源是否正常合法,常用于内网中

123 #PidFile /var/run/sshd.pid#放置SSHD这个PID文档的地点

(4)服务的开启、关闭及状态的查看

方法1

[root@zhao1 ~]# service sshd status/start/stop/restart

方法2
[root@zhao1 ~]# /etc/init.d/sshd status/start/stop/restart

服务开机状态的设定

[root@zhao1 ~]# chkconfig --list sshd#服务状态的查看

sshd           0:off1:off2:on3:on4:on5:on6:off

[root@zhao1 ~]# chkconfig sshd on#服务开机自动开启

[root@zhao1 ~]# chkconfig sshd off#服务开机自动关闭

(5)SSH远程登录

连接方式:ssh [远程主机用户名]@[远程服务器主机名或IP地址]

方式1root用户远程登录

[root@zhao1 ~]# ssh 192.168.1.212

方式2:普通用户远程登录

[root@zhao1 ~]# ssh mk@192.168.1.212

说明:

第一次登录服务器时系统没有保存远程主机的信息,为了确定该主机的身份会提示用户是否继续连接,输入yes后,这时系统会将服务器的信息写入用户主目录的$HOME/.ssh/known_hosts文件中,下次再次登录时就不会提示次信息了。

克隆后的虚拟机,默认网卡会变为eth1,执行以下命令可以修改为eth0

[root@zhao1 ~]# rm -fr /etc/udev/rules.d/70-persistent-net.rules

(6)通过密钥进行sshd服务认证

实验环境:

服务端:zhao1/192.168.1.211

客户端:zhao2/192.168.1.212

第一步:客户端生成密钥对

[root@zhao2 ~]# ssh-keygen

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:

cb:32:17:d1:5a:3f:e9:52:dc:03:18:75:99:7c:2a:1e root@zhao2

The key‘s randomart image is:

+--[ RSA 2048]----+

|          .....o |

|         . o .+ .|

|        . + .  o |

|         + oE+.  |

|        S  .*oo  |

|       . o o.. . |

|      o + . .    |

|       +   .     |

|                 |

+-----------------+

[root@zhao2 ~]# cd /root/.ssh/

[root@zhao2 .ssh]# ls

id_rsa  id_rsa.pub

第二步:发布公钥

使用 ssh-copy-id命令将客户端的公钥发布到远程服务器192.168.1.211,可以使用-i参数指定本地公钥存放的位置。

[root@zhao2 .ssh]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.1.211

The authenticity of host ‘192.168.1.211 (192.168.1.211)‘ can‘t be established.

RSA key fingerprint is d5:fb:5b:0e:df:9d:37:aa:17:42:1d:b5:39:9f:b1:e3.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added ‘192.168.1.211‘ (RSA) to the list of known hosts.

root@192.168.1.211‘s password:

Now try logging into the machine, with "ssh ‘root@192.168.1.211‘", and check in:

 

  .ssh/authorized_keys

 

to make sure we haven‘t added extra keys that you weren‘t expecting.

第三步:连接远程服务器

[root@zhao2 .ssh]# ssh root@192.168.1.211

[root@zhao1 ~]#

(7)实现两台服务器之间数据的复制

SCP源地址目标地址

SCP命令:基于ssh登录并复制数据,复制过程很安全,操作起来很方便。

[root@zhao1 ~]# scp /etc/passwd root@192.168.1.212:/mnt

root@192.168.1.212‘s password:

passwd         


本文出自 “12025595” 博客,转载请与作者联系!

1.SSHD服务

标签:待完善

原文地址:http://12035595.blog.51cto.com/12025595/1961585

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!