• linux9&11&12


    ########################

    ####9.openssh-server####

    ########################

    ####1.openssh-server####

    功能:让远程主机可以通过网络访问sshd服务,开始一个安全shell

    ####2.客户端连接方式####

    ssh 远程主机用户@远程主机ip

    ssh 远程主机用户@远程主机ip -X ##调用远程主机图形工具

    ssh     远程主机用户@远程主机ip command ##直接在远程主机运行某条命令

    eg:

    [kiosk@foundation41 Desktop]$ ssh root@172.25.254.141  ##以ip地址为172.25.254.141上的root身份远程连接该主机

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

    ECDSA key fingerprint is eb:24:0e:07:96:26:b1:04:c2:37:0c:78:2d:bc:b0:08.

    Are you sure you want to continue connecting (yes/no)? yes

    Warning: Permanently added '172.25.254.141' (ECDSA) to the list of known hosts.

    root@172.25.254.141's password:

    Last login: Tue Mar 28 10:11:47 2017

    [root@localhost ~]# gedit    

    (gedit:2283): Gtk-WARNING **: cannot open display: ##不能调用远程主机图形工具

    [root@localhost ~]# exit

    登出

    Connection to 172.25.254.141 closed.

    [kiosk@foundation60 Desktop]$ ssh -X root@172.25.254.141 ##-x调用远程主机图形工具

    root@172.25.254.141's password:

    Last failed login: Tue Mar 28 10:16:06 EDT 2017 from 172.25.254.60 on ssh:notty

    There were 2 failed login attempts since the last successful login.

    Last login: Tue Mar 28 10:14:52 2017 from 172.25.254.60

    [root@localhost ~]# gedit      

    ** (gedit:2423): WARNING **: Couldn't connect to accessibility bus: Failed to connect to socket /tmp/dbus-LHkqG6zUOB: 拒绝连接

    ####3.sshkey加密####

    1.生成公钥私钥

    [yy@server0 ~]# ssh-keygen ##生成公钥私钥工具

    Generating public/private rsa key pair.

    Enter file in which to save the key (/home/yy/.ssh/id_rsa):[enter] ##加密字符保存文件(建议用默认)

    Created directory '/home/yy/.ssh'.

    Enter passphrase (empty for no passphrase): [enter] ##密钥密码,必须>4个字符

    Enter same passphrase again: [enter] ##确认密码

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

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

    The key fingerprint is:

    ab:3c:73:2e:c8:0b:75:c8:39:3a:46:a2:22:34:84:81 yy@server0.example.com

    The key's randomart image is:

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

    |o                |

    |E.               |

    |..               |

    |.  . o           |

    |.o. * . S        |

    |oo.o o   .       |

    |+ =. .  .        |

    |o. oo.+..        |

    |    ..o*.        |

    +-----------------+

    [yy@server0 ~]# ls  /home/yy/.ssh/

    id_rsa  id_rsa.pub

    id_rsa ##私/ssh钥,就是钥匙

    id_rsa.pub ##公钥,就是锁

    2.添加key认证方式

    [root@server0 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub  root@172.25.0.11

    ssh-copy-id ##添加key认证方式的工具

    -i ##指定加密key文件

    /root/.ssh/id_rsa.pub ##加密key

    root ##加密用户为root

    172.25.0.11 ##被加密主机ip

    eg:

    [yy@localhost ~]$ ssh-copy-id -i /home/yy/.ssh/id_rsa.pub kiosk@172.25.254.41

    /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: ERROR: ssh: connect to host 172.25.254.241 port 22: No route to host

    3.分发钥匙给client主机

    [root@server0 ~]# scp /root/.ssh/id_rsa root@172.25.0.10:/root/.ssh/

    eg:

    eg:[yy@localhost ~]$ su -

    Password:

    Last login: Sun Mar 26 23:23:11 EDT 2017 on :0

    [root@localhost ~]# vim /etc/ssh/sshd_config   ###进入编辑状态,79 PasswordAuthentication yes,yes改成no

    [root@localhost ~]# systemctl restart sshd.service

    [root@localhost ~]# exit

    logout

    [yy@localhost ~]$ scp /home/yy/.ssh/id_rsa kiosk@172.25.254.41:/home/kiosk/.ssh/   ###分发钥匙给主机kiosk用户

    id_rsa                                        100% 1675     1.6KB/s   00:00    

    [yy@localhost ~]$

    4.测试

    [kiosk@desktop41 ~]# ssh yy@172.25.0.241 ##通过id_rsa直接连接不需要输入用户密码

    Last login: Mon Oct  3 03:58:10 2016 from 172.25.0.250

    [root@server0 ~]#

    ####4.提升openssh的安全级别####

    1.openssh-server配置文件

    [root@localhost ~]# vim /etc/ssh/sshd_config    ###进入编辑状态

    78 PasswordAuthentication yes|no ##是否开启用户密码认证,yes为支持no为关闭

    48 PermitRootLogin yes|no ##是否允许超级用户登陆

    49 AllowUsers student westos ##用户白名单,只有在名单中出现的用户可以使用sshd建立shell

    50 DenyUsers westos ##用户黑名单

    eg:

    [root@localhost ~]# vim /etc/ssh/sshd_config   ###进入编辑状态,48 PermitRootLogin no,不允许超级用户登陆

    [root@localhost ~]# systemctl restart sshd.service

    [kiosk@foundation42 ~]$ ssh root@172.25.254.242   ###密码正确输入三次,超级用户无法登录

    root@172.25.254.241's password:

    Permission denied, please try again.

    root@172.25.254.241's password:

    Permission denied, please try again.

    root@172.25.254.241's password:

    Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).

    [root@localhost ~]# vim /etc/ssh/sshd_config   ###进入编辑状态,50 Denyusers student,用户黑名单,不允许student用户登陆

    [root@localhost ~]# systemctl restart sshd.service

    [kiosk@foundation42 ~]$ ssh student@172.25.254.241   ###密码正确输入三次,student用户无法登录

    student@172.25.254.241's password:

    Permission denied, please try again.

    student@172.25.254.241's password:

    Permission denied, please try again.

    student@172.25.254.241's password:

    Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).

    [root@localhost ~]# vim /etc/ssh/sshd_config   ###进入编辑状态,49 Allowusers student,用户白名单,只允许登陆student用户

    [root@localhost ~]# systemctl restart sshd.service

    [kiosk@foundation42 ~]$ ssh student@172.25.254.241    ###student用户在白名单上,可以登陆

    student@172.25.254.241's password:

    Last failed login: Sun Mar 26 23:46:33 EDT 2017 from 172.25.254.42 on ssh:notty

    There were 3 failed login attempts since the last successful login.

    [student@localhost ~]$ exit

    登出

    Connection to 172.25.254.241 closed.

    [kiosk@foundation42 ~]$ ssh yy@172.25.254.242   ###yy用户不在白名单上,无法登陆

    yy@172.25.254.241's password:

    Permission denied, please try again.

    yy@172.25.254.241's password:

    Permission denied, please try again.

    yy@172.25.254.241's password:

    Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).

    ###################

    ####11.管理网络####

    ###################

    ####1.ip基础知识####

    1.ipv4

    2进制32位-----10进制

    172.25.0.10/255.255.255.0

    172.25.0.10:ip地址

    255.255.255.0:子网掩码

    子网掩码255位对应的ip位为网络位

    子网掩码0对应的ip位为主机位

    ####2.配置ip####

    <<图形化>>

    1.图形界面

    nm-connection-editor

    2.文本化图形

    nmtui  

    <<命令>>

    ifconfig 网卡 ip netmask ##临时设定

    nmcli connection add type ethernet con-name westos ifname eth0 autoconnect yes

    nmcli connection add type ethernet con-name westos ifname eth0 ip4 ip/24

    nmcli connection delete westos

    nmcli connection show

    nmcli connection down westos

    nmcli connection up westos

    nmcli connection modify "westos" ipv4.addresses newip/24

    nmcli connection modify "westos" ipv4.method <auto|manual>

    nmcli device connect eth0

    nmcli device disconnect eth0

    nmcli device show

    nmcli device status

    <<文件>>

    dhcp  ##动态获取

    vim /etc/sysconfig/network-scripts/ifcfg-eth0

    DEVICE=eth0     ##接口使用设备

    BOOTPROTO=dhcp ##网卡工作模式

    ONBOOT=yes        ##网络服务开启时自动激活

    NAME=eth0 ##网络接口名称

    wq

    systemctl restart network

    static|none              ##静态网络

    vim /etc/sysconfig/network-scripts/ifcfg-eth0

    DEVICE=eth0    ##设备

    BOOTPROTO=static|none  ##设备工作方式

    ONBOOT=yes              ##开启网络服务激活设备

    NAME=eth0              ##网络接口名称

    IPADDR=172.25.0.100                ##IP

    NETNASK=255.255.255.0 | PREFIX=24       ##子网掩码

    ####3.gateway 网关####

    1.路由器

    主要功能是用来作nat的

    dnat 目的地地址转换

    snat 源地址转换

    2.网关

    路由器上和自己处在同一个网段的那个ip

    3.设定网关

    systemctl stop NetwrokManager

    vim /etc/sysconfig/network               ##全局网关

    GATEWAY=网关ip

    vim /etc/sysconfig/network-scripts/ifcfg-网卡配置文件       ##网卡接口网关

    GATEWAY=网关ip

    systemctl restart netwrok

    route -n ##查询网关

    Kernel IP routing table

    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

    0.0.0.0   (网关)172.25.0.254    0.0.0.0         UG    0      0        0 eth0

    172.25.0.0      0.0.0.0         255.255.255.0   U     0      0        0 eth0

    ####5.dns####

    1.dns

    dns是一台服务器

    这太服务器提供了回答客户主机名和ip对应关系的功能

    2.设定dns

    vim /etc/resolv.conf

    nameserver dns服务器ip

    eg:nameserver 172.25.254.254

    vim /etc/sysconfig/network-scripts/ifcfg-网卡配置文件

    DNS1=dns服务器ip

    3.本地解析文件

    vim /etc/hosts

    ip 主机名称

    4.本地解析文件和dns读取的优先级调整

    /etc/nsswitch.conf

     38 #hosts:     db files nisplus nis dns

     39 hosts:      files dns ##files代表本地解析文件,dns代表dns服务器,那个在前面那个优先

    5.dhcp服务的配置

    linux11:

    1.在系统中创建set-ip-tool命令要求如下

    当在系统中执行set-ip-tool 172.25.254.x 后

    *)会自动显示ifconfig命令的输出

    *)系统ip被设定为:172.25.254.X

    [root@localhost Desktop]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

    [root@localhost Desktop]# systemctl restart network

    #vim编辑内容:

    DEVICE=eth0

    BOOTPROTO=static

    ONBOOT=yes

    NAME=eth0

    IPADDR=172.25.254.242

    NETNASK=255.255.255.0

    *)系统网关被设定为:172.25.254.250

    [root@localhost Desktop]# vim /etc/sysconfig/network

    #vim编辑内容:GATEWAY=172.25.254.250

    [root@localhost Desktop]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

    #vim编辑内容:GATEWAY=172.25.254.250

    [root@localhost Desktop]# systemctl restart network

    *)系统dns被设定为:172.25.254.250

    [root@localhost Desktop]# vim /etc/resolv.conf

    #vim编辑内容:nameserver 172.25.254.250

    [root@localhost Desktop]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

    #vim编辑内容:DNS1=172.25.254.250

    [root@localhost Desktop]# vim /etc/resolv.conf

    #vim编辑内容:nameserver 172.25.254.250

    [root@localhost Desktop]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

    #vim编辑内容:DNS1=172.25.254.250

    #################################

    ####12.不同系统之间的文件传输####

    #################################

    ####1.文件归档####

    1.

    文件归档,就是把多个文件变成一个归档文件

    2.

    tar c ##创建

    f ##指定归档文件名称

    t ##显示归档文件中的内容

    r ##向归档文件中添加文件

    --get ##取出单个文件

    --delete ##删除单个文件

    x ##取出归档文件中的所有内容

    -C ##指定解档目录

    -z ##gz格式压缩

    -j ##bz2格式压缩

    -J ##xz格式压缩

    eg:[root@foundation41 ~]# tar cf etc.tar /etc/  ##把etc下的内容归档etc.tar到当前目录

    [root@foundation41 ~]# du -sh /etc/

    35M /etc/

    [root@foundation41 ~]# du -sh etc.tar   ##压缩后文件的大小

    31M etc.tar

    [root@foundation41 mnt]# tar tf etc.tar file   ##显示归档文件etc.tar中file文件内容

    [root@foundation41 mnt]# tar rf etc.tar file    ##向归档文件etc.tar中添加file文件

    [root@foundation41 mnt]# tar f etc.tar --get file ##从归档文件etc.tar取出file文件

    [root@foundation41 mnt]# tar xf etc.tar ##显示归档文件etc.tar中所有文件内容

    [root@foundation41 mnt]# tar f etc.tar --delete file  ##从归档文件etc.tar中删除file

    [root@foundation41 mnt]# tar xf /mnt/etc.tar -C /root/Desktop/  ##把/mnt/etc.tar解压到桌面

    ####2.压缩####

    gz

    gzip etc.tar ##压缩成gz格式

    gunzip  etc.tar.gz ##解压gz格式压缩包

    tar zcf etc.tar.gz /etc ##把文件归档为tar并压缩成gz

    tar zxf etc.tar.gz ##解压并解档gz格式压缩包

    eg:

    [root@localhost Desktop]# gzip etc.tar    ###将etc.tar压缩成gz格式

    [root@localhost Desktop]# ls

    etc  etc.tar.gz

    [root@localhost Desktop]# du -sh etc.tar.gz    ###压缩后变小

    8.4M etc.tar.gz

    [root@localhost Desktop]# gunzip etc.tar.gz    ###解压

    [root@localhost Desktop]# ls

    etc  etc.tar

    bz2

    bzip2 etc.tar ##压缩成bz2格式

    bunzip2 etc.tar.bz2 ##解压bz2格式压缩包

    tar jcf etc.tar.bz2 /etc ##把文件归档为tar并压缩成bz2

    tar jxf etc.tar.bz2 ##解压并解档bz2格式压缩包

    xz

    xz etc.tar ##压缩成xz格式

    unxz  etc.tar.xz ##解压xz格式压缩包

    tar Jcf etc.tar.xz /etc ##把文件归档为tar并压缩成zx

    tar Jxf etc.tar.xz ##解压并解档xz格式压缩包

    zip

    zip -r etc.tar.zip etc.tar ##压缩成zip格式

    unzip etc.tar.zip ##解压zip格式压缩包

    ####3.系统中的文件传输####

    scp file username@ip:/dir ##上传

    scp    username@ip:/dir/file  /dir ##下载

    rsync [参数] file username@ip:/dir             ****************

    rsync -r ##同步目录

    -l ##不忽略链接

    -p ##不忽略文件权限

    -t ##不忽文件时间戳

    -g ##不忽文件所有组

    -o ##不忽文件所有人

    -D ##不忽略设备文件

    linux12:

    1.在server主机中把/etc目录打包压缩到/mnt中,名字为etc.tar.gz

    server主机中:

    [root@localhost Desktop]#tar zcf /mnt/etc.tar.gz /etc

    2.复制server主机中的etc.tar.gz到desktop主机的/mnt中

    desktop主机中:

    [root@localhost Desktop]#scp yyserver@172.25.254.241:/mnt/etc.tar.gz /mnt

    3.同步server主机中的/etc中的所有文件到desktop主机中/mnt中,包含链接文件

    server主机中:

    [root@localhost Desktop]#rsync -rl /etc/ root@172.25.254.141:/mnt

  • 相关阅读:
    程序员计算器HEX、EDC、OCT等等的意思
    MFC的程序,不想显示窗口,任务栏里也不显示
    收藏一个在线思维导图的制作网站
    vs code打开文件显示的中文乱码
    vs strcore.cpp(156) 内存泄漏
    Win10控制桌面图标显示
    windows10系统激活方法
    NSIS增加打包文件夹
    NLP之电影评分数据的情感分析
    python之scrapy模拟登陆人人网
  • 原文地址:https://www.cnblogs.com/yangying2017/p/6637835.html
Copyright © 2020-2023  润新知