• ssh以及双机互信


      当我们要远程到其他主机上面时就需要使用ssh服务了。

    我们就来安装一下sshd服务以及ssh命令的使用方法。

    服务安装:

    需要安装OpenSSH 四个安装包:

    安装包:

    openssh-5.3p1-114.el6_7.x86_64:包含OpenSSH服务器及客户端需要的核心文件

    openssh-clients-5.3p1-114.el6_7.x86_64:OpenSSH客户端软件包

    openssh-server-5.3p1-114.el6_7.x86_64:OpenSSH服务器软件包

    openssh-askpass-5.3p1-114.el6_7.x86_64:支持对话框窗口的显示,是一个基于X 系统的密码

    openssh-clients是作为客户端必须安装的包,openssh-server是作为服务端必须安装的包。

    实验环境:

    ip:192.168.1.63   作为服务端

    ip:192.168.1.64   作为客户端

    我们可以查看服务器是否安装openssh包。

    [root@tiandong63 ~]# yum install openssh openssh-clients openssh-server -y

    [root@tiandong63 ~]# /etc/init.d/sshd start

    [root@tiandong63 ~]# chkconfig sshd on
    [root@tiandong63 ~]# chkconfig --list sshd
    sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

    安装完成后我们查看是否安装

    [root@tiandong63 ~]# rpm -qa |grep openssh
    openssh-5.3p1-94.el6.x86_64
    openssh-server-5.3p1-94.el6.x86_64
    openssh-clients-5.3p1-94.el6.x86_64

    查看安装的路径:

    [root@tiandong63 ~]# rpm -ql openssh
    /etc/ssh     #主安装目录
    /etc/ssh/moduli
    /usr/bin/ssh-keygen
    /usr/libexec/openssh
    /usr/libexec/openssh/ssh-keysign

    .......

    [root@tiandong63 ~]# ll /etc/ssh/      #查看一下主安装目录下的文件
    total 156
    -rw-------. 1 root root 125811 Nov 23 2013 moduli
    -rw-r--r--. 1 root root 2047 Nov 23 2013 ssh_config      #客户端的配置文件
    -rw-------. 1 root root 3879 Nov 23 2013 sshd_config    #服务端的配置文件
    -rw-------. 1 root root 672 Mar 19 06:36 ssh_host_dsa_key
    -rw-r--r--. 1 root root 590 Mar 19 06:36 ssh_host_dsa_key.pub
    -rw-------. 1 root root 963 Mar 19 06:36 ssh_host_key
    -rw-r--r--. 1 root root 627 Mar 19 06:36 ssh_host_key.pub
    -rw-------. 1 root root 1675 Mar 19 06:36 ssh_host_rsa_key
    -rw-r--r--. 1 root root 382 Mar 19 06:36 ssh_host_rsa_key.pub

    此处不对配置文件做详细描述了,如果大家对配置文件有兴趣的话可以一块探讨一下。

    此处在服务端做如下操作,在客户端也做如下操作。(在客户端上安装完成之后就可以远程了)

    我们从客户端上远程服务端:

    [root@tiandong64 ~]# ssh 192.168.1.63        此时输入密码后就可以远程到服务器上了
    root@192.168.1.63's password:
    Last login: Sun Mar 19 20:59:21 2017 from 192.168.1.105      

    [root@tiandong63 ~]# 

    此处我们来测试一下,如果服务器端没有安装openssh-server包的时候是否可以被远程呢。

    [root@tiandong63 ~]# rpm -e openssh-server     卸载了服务器端的openssh-server包
    [root@tiandong63 ~]# rpm -qa |grep openssh     查看没有了server包
    openssh-5.3p1-94.el6.x86_64
    openssh-clients-5.3p1-94.el6.x86_64

    现在在客户端上ssh

    [root@tiandong64 ~]# ssh 192.168.1.63
    ssh: connect to host 192.168.1.63 port 22: Connection refused

    在服务器端安装openssh-server包

    [root@tiandong63 ~]# rpm -qa |grep openssh
    openssh-5.3p1-94.el6.x86_64
    openssh-server-5.3p1-94.el6.x86_64
    openssh-clients-5.3p1-94.el6.x86_64

    此时在来远程:

    [root@tiandong64 ~]# ssh 192.168.1.63
    root@192.168.1.63's password:
    Last login: Sun Mar 19 21:21:58 2017 from 192.168.1.105
    [root@tiandong63 ~]#

    接下来讲一下双机互信,免秘钥登录。

    [root@tiandong64 ~]# ssh-keygen

    在本地生成了两个文件

    [root@tiandong64 .ssh]# ls
    id_rsa id_rsa.pub

    在本地生成了两个文件:

    此时生成了私钥和公钥,只需要把公钥传到客户机上就可以了。

    [root@tiandong64 .ssh]# ssh-copy-id -i 192.168.1.63

    此时在去远程,就可以免秘钥登录了。若要回复秘钥登录的话把传到目标端的文件删除了就可以了。

    [root@tiandong64 ~]# ssh 192.168.1.63
    Last login: Sun Mar 19 21:23:27 2017 from 192.168.1.64
    [root@tiandong63 ~]#

    在目标端删除公钥

    [root@tiandong63 .ssh]# pwd
    /root/.ssh
    [root@tiandong63 .ssh]# rm -rf authorized_keys

    在去远程,此时就需要秘钥了。

  • 相关阅读:
    hibernate 高并发下遇到的大坑
    Spring Cloud微服务架构企业中的应用
    spring cloud学习-hystrix
    点评CAT接入手册
    centOS6.5 修改catalina.sh使用crontab自动切割日志tomcat8
    mariaDB安装报错
    linux安装rap需要的软件
    mariaDB的innodb恢复报错解决
    NFinal学习笔记 02—NFinalBuild
    NFinal 视图—用户控件
  • 原文地址:https://www.cnblogs.com/winter1519/p/7384653.html
Copyright © 2020-2023  润新知