• 末学者笔记--SSHD服务及SCP用法


    sshd服务讲解

    1.SSHD服务

    介绍:SSH 协议:安全外壳协议。为 Secure Shell 的缩写。SSH 为建立在应用层和传输层基础上的安全协议。

    默认端口22

    作用

    sshd服务使用SSH协议可以用来进行远程控制, 或在计算机之间传送文件。

    相比较之前用telnet方式来传输文件要安全很多,因为telnet使用明文传输,是加密传输。——免密登录

    SSH服务安装

    这里用yum安装(系统已经默认安装并开机自启)

    ——yum -y install openssh openssh-clients openssh-server openssh-askpass

    SSH 配置文件

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

    ssh_config 为客户端配置文件

    sshd_config 为服务器端配置文件

    2.几个隐藏文件

    主节点:即执行ssh-keygen的主机

    ——ssh-keygen

    ——~]# ls .ssh/

    id_rsa  id_rsa.pub  known_hosts

    id_rsa: 私钥(执行ssh-keygen生成)

    id_rsa.pub: 公钥(执行ssh-keygen生成)

    known_hosts: 主机信息(未连接时没有此信息)

    从节点:接收秘钥的主机

    —— ls .ssh/

    authorized_keys

    authorized_keys文件内容和主节点的 id_rsa.pub文件内容一致,即保存了公钥信息。

    3.使用ssh免密登录远程主机

    如果用root进程登录远程主

    ——ssh  192.168.100.156

    第一次登录服务器时系统没有保存远程主机的信息,为了确认该主机身份会提示用户是否继续连

    接,输入yes 后登录,这时系统会将远程服务器信息写入用户主目录下的$HOME/.ssh/known_hosts 文件中,下次再进行登录时因为保存有该主机信息就不会再提示了

    4.生成密钥对

    输入ssh-keygen之后一直回车即可,生成一次即可,无需多次生成该密钥,否则会提示你是否覆盖选项!

    ——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:

    SHA256:uzrFboudR48UdBgDndOqvbCLuownTPF5P1vUQX0WbU4 root@ken

    The key's randomart image is:

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

    |        .oo=.. .o|

    |          *oo . E|

    |         . +.  * |

    |  .       o. .  .|

    |   o . .So...    |

    |  . o . =o+      |

    | o   . +.=.+     |

    |  oo. .+*++ .    |

    |  .o+o++B*       |

    +----[SHA256]-----+

    5.发送密钥

    使用ssh-copy-id加上ip地址即可传送密钥至想要登录的主机,需要输入一次客户端的密码

    ——ssh-copy-id 192.168.163.128

    /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"

    The authenticity of host '192.168.163.128 (192.168.163.128)' can't be established.

    ECDSA key fingerprint is SHA256:kV6tl/qBm50DhXUc0Q0bnavLwsUrYHT6VrdcivrsHyo.

    ECDSA key fingerprint is MD5:55:4c:2d:86:64:d4:9d:4b:eb:0e:b2:68:38:d5:dc:8c.

    Are you sure you want to continue connecting (yes/no)? yes/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

    root@192.168.163.128's password:

    Number of key(s) added: 1

    Now try logging into the machine, with:   "ssh '192.168.163.128'"

    and check to make sure that only the key(s) you wanted were added.

    6.登录节点

    在发送完密钥之后即可不需要输入密码即可访问节点

    如果节点不是默认的22端口,还需要机上小写 的p选项指定端口

    —— ssh 192.168.163.128

    Last login: Mon Mar 25 11:24:43 2019 from 192.168.163.130

    scp用法

    一.概念:

    scp可以实现远程主机之间的文件复制

    scp使用ssh协议,所有想要免密进行复制,需要发送秘钥(配置ssh给相应的节点。

    scp使用格式

    scp [user@]host1:]file1 ... [[user@]host2:]file2

    常用选项:

    -r: 复制目录时使用

    -P:大写的P指定端口

    二.scp发送主机文件到远程节点

    —— ls

    anaconda-ks.cfg    test

    ——scp  /root/test 192.168.64.5:/tmp

    test                                              100%    0     0.0KB/s   00:00    

    三.scp拉取远程节点文件到本地

    ——#scp  192.168.64.7:/root/test  /tmp/

    root@192.168.64.7's password:

    test                                                                                                100%    0     0.0KB/s   00:00    

    四.scp复制本地目录到远程节点

    —— scp feige 192.168.64.7:/root/

    root@192.168.64.7's password: feige: not a regular file

    —— scp -r feige 192.168.64.7:/root/    #需要加上选项-r

    root@192.168.64.7's password:

    五.scp远程节点目录到本机

    —— scp -r  root@192.168.64.7:/tmp/test /tmp/      #在root下时可省略root@

    root@192.168.64.7's password:

    —— ls /tmp

    test

    末学后进,微羽成鳞~
  • 相关阅读:
    最小生成树问题-prim算法求解
    排序算法7---快速排序算法
    IOS工作笔记(九)
    NSUserDefaults的一些用法
    UIActionSheet的简单使用
    如何处理过多使用懒加载的问题?
    prefix.pch文件的一些简单使用
    IOS工作笔记(八)
    登录时本地保存账号密码及关闭ARC的方法
    IOS页面跳转的方法
  • 原文地址:https://www.cnblogs.com/feige2L/p/10731721.html
Copyright © 2020-2023  润新知