zoukankan      html  css  js  c++  java
  • 1.SSH协议学习笔记

    一、SSH介绍

    • 介绍: SSH全称是Secure Shell,安全外壳协议。
    • 端口号:22;

    如何查看服务端口号:
    grep ssh /etc/services
    netstat -antup | grep ssh
    lsof -i:22

    • 作用:sshd服务使用SSH协议可以用来进行远程控制, 或在计算机之间传送文件。
    • 验证方式:1、基于口令 2、基于密钥安全验证(后文将结合expect详细介绍SSH免密登录及批量配置管理)
    • telnet使用明文传输,ssh加密传输

    二、SSH服务安装

    1、需要安装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 系统的密码
    诊断工具

    2、 两种安装方式

     yum install openssh openssh-clients openssh-server -y
     rpm –ivh /media/cdrom/Packages/openssh*.rpm
     	#rpm方式安装可能需要解决依赖关系
    

    3、确认软件包是否安装

    rpm -qa | grep openssh #确认软件包是否安装
    rpm -qc openssh-server #查看已安装软件的配置文件
    rpm -qf `which ssh` #验证文件所属软件包
    

    三、sshd服务配置和管理

    1、OpenSSH配置文件:

    常用配置文件有两个/etc/ssh/ssh_config/etc/sshd_config

    • ssh_config为客户端配置文件
    • sshd_config为服务器端配置文件

    2、服务启动关闭脚本:

    #service sshd restart/stop/start/status
    #systemctl restart/stop sshd
    #systemctl list-unit-files |grep ssh [检查ssh是否开机自启]
    

    3、sshd服务日志存放在:/var/log/secure
    4、SSH配置调优

    vim /etc/ssh/sshd_config
    `Port 22` #设置sshd监听端口号
    ListenAddress 0.0.0.0 #设置绑定IP,0.0.0.0 表示侦听所有地址
    Protocol 2 #安全考虑,设置为最新的协议版本
    #HostKey /etc/ssh/ssh_host_key #设置包含计算机私人密匙的文件
    LoginGraceTime 2m  #进行输入密码时的停留时间
    `PermitRootLogin yes` #允许以root远程登录
    PasswordAuthentication yes #验证方式为密码认证
    PermitEmptyPasswords no #不允许空密码登录
    # PrintMotd yes #登入后的提示信息
    echo 'Warning ! From now on, all of your operation has been record!'> /etc/motd
    # PrintLastLog yes    # 显示上次登入的信息!预设也是 yes
    `UseDNS no` #判断客户端来源是正常合法的,因此会使用 DNS 去反查客户端的主机名
    

    四、SSH工作原理

    直接看图吧!

    qinlulu
    第一次登录server时,由于本机未保存server的信息,因此会提示用户是否继续连接,输入yes后登录。同时将远程server写入用户主目录下的$HOME/.ssh/knows.hosts中。

    五、免密登录

    此次实验目标是:A(10.43.190.251) 能免密登录 B(10.43.190.252)
    要在 Linux 中设置 SSH 免密登录,您只需生成公钥并将其附加到远程主机 ~/.ssh/authorized_keys 文件即可。.

    以下步骤将介绍配置 SSH 免密登录的过程:

    1. 检查现有的 SSH 密钥对。

    ls -al ~/.ssh/id_*.pub
    如果存在现有密钥,您可使用这些密钥并跳过步骤2或者备份旧密钥并生成新密钥

    1. 生成新密钥对:ssh-keygen

    以下命令将生成一个新的 4096 位 SSH 密钥对,并将您的电子邮件地址作为注释:
    ssh-keygen -t rsa -b 4096 -C "your_email@domain.com"
    按 Enter 接受则默认文件位置和文件名:

    Enter file in which to save the key (/home/yourusername/.ssh/id_rsa):

    接下来,ssh-keygen 工具将要求您键入安全密码。无论您是否想要使用密码短语都取决于您,如果您选择使用密码短语,您将获得额外的安全保护。在大多数情况下,开发人员和系统管理员使用 SSH 而不使用密码,因为它们对完全自动化的流程很有用。如果您不想使用密码短语,请按 Enter

    Enter passphrase (empty for no passphrase):

    整个交互看起来像这样:
    qinlulu

    确认已经生成 SSH 密钥:

    ls ~/.ssh/id_*

    1. ssh-copy-id把A的公钥发送给B

    默认用法:
    在A服务器上,ssh-copy-id root@10.43.190.252

    如果由于某种原因, ssh-copy-id 无法正常使用,则可以使用以下命令复制公钥:(在A服务器上执行)
    cat ~/.ssh/id_rsa.pub | ssh root@10.43.190.252 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

    1. 使用 SSH 密钥登录服务器
      qinlulu如果一切顺利,您将立即登录。

    更多IT技术,请微信搜索公众号“秦露露”或者扫描下方二维码关注
    在这里插入图片描述

    十年磨一剑
  • 相关阅读:
    实例属性 类属性 实例域 类域
    研究数据集
    static 静态域 类域 静态方法 工厂方法 he use of the static keyword to create fields and methods that belong to the class, rather than to an instance of the class 非访问修饰符
    accessor mothod mutator mothod 更改器方法 访问器方法 类的方法可以访问类的任何一个对象的私有域!
    上钻 下钻 切片 转轴 降采样
    识别会话
    Performance Tuning Using Linux Process Management Commands
    Secure Hash Algorithm 3
    grouped differently across partitions
    spark 划分stage Wide vs Narrow Dependencies 窄依赖 宽依赖 解析 作业 job stage 阶段 RDD有向无环图拆分 任务 Task 网络传输和计算开销 任务集 taskset
  • 原文地址:https://www.cnblogs.com/qinlulu/p/12270266.html
Copyright © 2011-2022 走看看