zoukankan      html  css  js  c++  java
  • CentOS4.1下的SSH的安装,配置,使用

    我们现在用的大都是openssh,在系统安装是都默认安装好了,所以只要配置下公钥,私钥就可以了.下面来谈谈配置,ssh每执行一条命令,都要输入密码,很繁琐,不过有一种用密钥对来验证的方式.下面写出我生成密匙对的过程:

    1. 命令:$ssh-keygen -t rsa

    说明:生成密匙对,我用的是rsa的密钥,输入此命令后会提示:

    Generating public/private rsa key pair.

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

    不要输入继续敲回车,会提示:

    Enter passphrase (empty for no passphrase):

    不要输入继续敲回车,会提示:

    Enter same passphrase again:

    不要输入继续敲回车,会提示:

    Your identification has been saved in /home/liuy/.ssh/id_rsa.

    Your public key has been saved in /home/liuy/.ssh/id_rsa.pub.

    The key fingerprint is:

    bb:45:d7:7b:58:55:0c:d9:5a:0d:c8:8b:2b:d0:4d:b2 liuy@HFINMSP3

    生成的过程中提示输入密钥对保存位置,直接回车,接受默认值就行了。接着会提示输入一个不同于你的password的密码,直接回车,让它空着。当然,也可以输入一个。(我比较懒,不想每次都要输入密码。) 这样,密钥对就生成完了,其中公共密钥保存在 ~/.ssh/id_rsa.pub,私有密钥保存在 ~/.ssh/id_rsa

    2. 命令:$chmod 755 .ssh

    说明:改一下 .ssh 目录的权限

    3. 命令:scp ~/.ssh/id_rsa.pub liuy@192.168.1.3:/home/liuy/.ssh/authorized_keys

    说明:3.1 把这个密钥对中的公共密钥复制到你要访问的机器上去,并保存为~/.ssh/authorized_keys

    这样就大功告成了,测试下,输入:$ssh liuy@192.168.1.3,第一次登陆这个ip要输入密码,以后就不用输入密码直接就登陆了.

    3.2 如果192.168.1.3机器上别的用户已经生成的authorized_keys,你就不要把别人的公钥覆盖了,用以下的命令

    scp ~/.ssh/id_rsa.pub netcool@192.168.1.3:~/.ssh/liuyou.key

    ssh netcool@192.168.1.3 "cat ~/.ssh/liuyou.key >> ~/.ssh/authorized_keys"

    4. ssh支持root用户远程登陆

    5. 使用,生成公钥,copy到远程机器

    make_pubkey.sh的脚本:

    #!/bin/bash

    # city.txt 的内容如下:

    #滁洲,CZINMSP,192.74.8.13,192.74.8.14

    #合肥,HFINMSP,192.65.135.2,192.65.135.3

    #蚌埠,BBINMSP,192.66.8.233,192.66.8.235

    #芜湖,WHINMSP,192.67.8.61,192.67.8.62

    update_key(){

    cityfile="city.txt"

    ips=`awk -F"," '{ print $3 }' $cityfile`

    for ip in $ips

    do

    echo $ip

    scp ~/.ssh/id_rsa.pub netcool@$ip:~/.ssh/liuyou.key

    ssh netcool@$ip "cat ~/.ssh/liuyou.key >> ~/.ssh/authorized_keys"

    done

    }

    update_key

  • 相关阅读:
    Spring Boot 系列(九)数据层-集成Spring-data-jpa
    Spring Boot 系列(八)@ControllerAdvice 拦截异常并统一处理
    Spring Boot 系列(七)Swagger2-生成RESTful接口文档
    Spring Boot 系列(六)web开发-Spring Boot 热部署
    Spring Boot 系列(五)web开发-Thymeleaf、FreeMarker模板引擎
    Spring Boot 系列(四)静态资源处理
    查看oracle中表的索引
    freemarker模板加载TemplateLoader常见方式
    servlet的生命周期详解
    eclipse 自动创建web.xml
  • 原文地址:https://www.cnblogs.com/liuyou/p/2214499.html
Copyright © 2011-2022 走看看