• linux配置ssh公钥认证,打通root用户的免密码输入的scp通道


    1.ssh-keygen

         ssh-keygen是unix-like系统的一个用来生成、管理ssh公钥和私钥的工具。


    2.用法

    常用的重要的选项有:

    -b num   指定生成多少比特长度的key,单位为b,默认为1024b

    -t    指定生成key的类型,也就是使用哪一种加密算法,可选的有rsa1 | rsa | dsa

    3.

    [root@iDirector ~]# 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:
    23:12:af:af:37:ea:e5:2d:49:63:97:27:d4:bf:2d:75 root@iDirector
    The key's randomart image is:
    +--[ RSA 2048]----+
    |                 |
    |                 |
    |    .    .       |
    |     o  . .      |
    |    . o.S. .     |
    |     o+.+.. . . E|
    |    .o.+ o   + . |
    |     +=.    o .  |
    |   .++oo.    .   |
    +-----------------+
    [root@iDirector ~]# ll /root/.ssh/
    id_rsa       id_rsa.pub   known_hosts 
    在程序提示输入passphrase时直接输入回车,表示无证书密码。 上述命令将生成私钥证书id_rsa和公钥证书id_rsa.pub,存放在用户家目录的.ssh子目录中。 


    转载自:http://www.361way.com/ssh-public-key/3662.html

    在两台linux主机上由于环境的需要,经常要配置两台主机之间免密码登录,这就要用到key认证,也就是所谓的公私钥认证。
    便于理解,我这里指定两台主机为 A 和 B 。如果A主机想免密码登录到B主机上,则A主机上存放私钥,B 主机上存放公钥。
    通过ssh-keygen 命令生成的两个文件为:公钥文件 ~/.ssh/id_rsa.pub; 私钥文件 ~/.ssh/id_rsa 。
    而B主机上存放公钥时,需要将id_rsa.pub的内容存放到~/.ssh/authorized_keys 文件内,并且保证权限为600

        #将key导入到远程的B主机上,并修改权限
       #在A主机上操作
    $ cat /root/.ssh/id_rsa.pub | ssh root@远程服务器ip 'cat - >> ~/.ssh/authorized_keys' #B主机上操作 $ chmod 600 ~/.ssh/authorized_keys

    不过还有更简单的方法,不需要在B主机上再修改权限 ,而直接将公钥内容导入到远程主机上,使用ssh-copy-id命令,如下:

    $ ssh-copy-id  -i /root/.ssh/id_rsa root@xxx,xxx,xxx,xxx

    配置完key后,需要在sshd_config文件中开启key认证

        $ vim /etc/ssh/sshd_config
        PubkeyAuthentication yes  //将该项改为yes    

    修改完成后,通过/etc/init.d/sshd restart 重启ssh服务重新加载配置。如果想要禁用密码认证,更改如下项:

        $ vim /etc/ssh/sshd_config
        UsePAM yes
        为
        UserPAM no

    转载自:http://blog.csdn.net/aabbcc456aa/article/details/18981279

    如何让连接新主机时,不进行公钥确认?

    在首次连接服务器时,会弹出公钥确认的提示。这会导致某些自动化任务,由于初次连接服务器而导致自动化任务中断。或者由于  ~/.ssh/known_hosts 文件内容清空,导致自动化任务中断。 SSH 客户端的 StrictHostKeyChecking 配置指令,可以实现当第一次连接服务器时,自动接受新的公钥。只需要修改 /etc/ssh/ssh_config 文件,包含下列语句:

    Host *
     StrictHostKeyChecking no

    或者在 ssh 命令行中用 -o 参数

    $ ssh  -o StrictHostKeyChecking=no  192.168.0.110

     

  • 相关阅读:
    2020牛客寒假算法基础集训营3
    2020牛客寒假算法基础集训营2
    2020牛客寒假算法基础集训营1
    Educational Codeforces Round 81 + Gym 102267
    博客迁移到自己的WordPress站上
    HDU 5172 GTY's gay friends 线段树 or Hash
    HDU 3436 Queue-jumpers Splay
    HDU 1890 Robotic Sort Splay
    POJ 3468 A Simple Problem with Integers Splay
    BZOJ 1503 郁闷的出纳员 Splay
  • 原文地址:https://www.cnblogs.com/blitheG/p/7603322.html
Copyright © 2020-2023  润新知