您的位置:首页 > 理论基础 > 计算机网络

linux基础命令之ssh的key认证和网络基础

2016-10-30 21:42 507 查看
#######################################################

#####################第九单元##########################

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

1.ssh的key认证

#######生成key###########

[test@foundation0 ~]$ ssh-keygen             ###生成公钥和私钥的工具

Generating public/private rsa key pair.

Enter file in which to save the key (/home/test/.ssh/id_rsa):『enter』 ###指定加密字符保存文件,使用默认

Created directory '/home/test/.ssh'.

Enter passphrase (empty for no passphrase):         ###密码,必须大于4位

Enter same passphrase again:

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

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

The key fingerprint is:                    ###确认密码

a5:4f:02:51:68:59:f4:e8:e3:c5:91:1f:6f:86:99:06 test@foundation0.ilt.example.com

The key's randomart image is:

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

|      .*+        |

|      +. o .     |

|     .. . E .    |

|       o + + *   |

|        S + * +  |

|       . * . o   |

|        . .      |

|                 |

|                 |

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

[test@foundation0 .ssh]$ pwd

/home/test/.ssh            ###生成密钥存放位置

[test@foundation0 .ssh]$ ls    

id_rsa  id_rsa.pub        ####id_rsa位私钥,id_rsa.pub位公钥

#####################使用key加密目标主机的目标用户############

[test@foundation0 ~]$  ssh-copy-id -i /home/test/.ssh/id_rsa.pub westos@172.25.254.100

The authenticity of host '172.25.254.100 (172.25.254.100)' 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

/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

westos@172.25.254.100's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'westos@172.25.254.100'"

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

ssh-copy-id        ####上传key的工具

-i            ####指定使用的公钥

/home/test/.ssh/id_rsa.pub    #####使用公钥的名称

westos            ####被管理的目标用户

172.25.254.100        ####被管理用户所在主机的ip

authorized_keys        ###此文件在目标用户加目录的.ssh中,这个文件就是目标用户被加密的标识,文件内容位公钥内容。

2.sshd服务的简单配置

vim /etc/ssh/sshd_config        ###sshd服务的配置文件

48 PermitRootLogin yes|no        ###是否允许root用户通过sshd的认证

78 PasswordAuthentication yes|no    ###开启或关闭用户密码认证

AllowUsers student westos        ###用户白名单,只允许在名单中出现的用户使用sshd服务

systemctl restart sshd            ###从新加载配置

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

##############第十单元################################

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

1.rsyslogd 服务

########服务功能#######

这个服务是用来管理系统日志的进程

########服务配置文件############

/etc/rsyslog.conf

#######服务配置############

vim /etc/rsyslog.conf

service.loglevel    logfile

*.*                     /var/log/all.log    ##所有服务的所有日志都放到/var/log/all.log中

######日志同步#####################

在日志接收方

vim /etc/rsyslog.conf

$ModLoad imudp            ###加载日志接收功能模块

$UDPServerRun 514        ###加载日志接收接口

在日志发送方

*.*        @日志接收方ip

做完配置重启rsyslogd服务

关闭火墙

systemctl stop firewalld

########日志分析###################

systemd-journald    ###日志分析进程

journalctl    ###日志分析命令

journalctl -n 5        ##查看最近生成的5条日志

journalctl -p err    ##查看系统报错

journalctl --since --until ###查看某个时间段生成的日志

journalctl -o verbose    ###查看日志能够使用的条件参数

journalctl    _UID=        ##进程uid

        _PID=        ##进程id

        _GID=        ##进程gid

        _HOSTNAME=    ##进程所在主机

        _SYSTEMD_UNIT=    ##服务名称

        _COMM=        ##命令名称

##########################日志监控工具的设定################3

默认情况下journalctl是无法看到关机之间产生的日志的

如果向检测到这类日志设置如下

[root@serverX ~]#mkdir /var/log/journal

[root@serverX ~]#chown root:systemd-journal /var/log/journal

[root@serverX ~]#chmod 2755 /var/log/journal

Send the USR1 signal to the systemd-journald or reboot serverX.

[root@serverX ~]#killall -USR1 systemd-journald

[root@serverX ~]#ls /var/log/journal/4513ad59a3b442ffa4b7ea88343fa55f

system.journal user-1000.journal

############################如何同步系统时间######################

1.确定时间源地址

172.25.254.254

2.确定客户主机使用的时间同步服务

chronyd.service

3.在chronyd.service服务中加载时间源地址

vim /etc/chrony.conf

server    172.25.254.254 iburst

systemctl restart chronyd.service

############################timedatectl###################

timedatectl list-timezones        ##列出时区

timedatectl set-timezone 时区        ##设定时区
timedatectl set-time HH:mm:ss        ##设定系统时间

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

#################第十一单元#############################

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

1.网络基础知识

一台主机如果可以连接公网,比如访问www.baidu.com

那么这台主机必然会有

ipaddress

GATEWAY

dns

############ipaddress##############

tcp/ip

ipv4

2进制32位

254.254.254.254/255.255.255.0

11111110.11111110.11111110.11111110/11111111.11111111.11111111.00000000

254.254.0.254/255.255.255.0

254.254.0.254/255.255.0.0

########ip设定###########

ifconfig    ###查看或者临时设定主机ip的工具

ifconfig 网络接口    ##查看这个接口上的 ip

ifconfig 网络接口 ip netmask 子网掩码    ####临时设定ip

ifconfig eth0 172.25.254.100 netmask 255.255.255.0

systemctl restart network    ###重新启动网络ifco    基本服务

systemctl restart NetworkManager    ###网络智能管理服务

图形网络配置方式

nm-connection-editor        ##图形中的网络设定工具

nmtui                ##文本中的网络设定工具

命令设定ip的方式

nmcli

nmcli connection delete    连接名称    ###删除此连接

nmcli connection add con-name westos ifname eth0 type ethernet autoconnect  yes     ####添加动态网络

nmcli connection add con-name westos ifname eth0 type ethernet ip4 ip/24    ###静态网络

网络配置文件

/etc/sysconfig/network-scripts/        ###网络配置目录

###动态网络配置###

vim ifcfg-xxx                ###网络配置文件格式

DEVICE=eth0                ##指定文件管理的设备名称

BOOTPROTO=dhcp        ##dhcp动态获取,none和static都表示静态网络

ONBOOT=yes                ##开机自动激活设备

NAME=hello
4000
                ##指定网络链接的名字为hello

###静态网络配置###

vim ifcfg-xxx                           ###网络配置文件格式

DEVICE=eth0                             ##指定文件管理的设备名称

BOOTPROTO=static|none            ##dhcp动态获取,none和static都表示静态网络

ONBOOT=yes                              ##开机自动激活设备

NAME=hello                ##指定链接名字

IPADDR=172.25.254.100            ##设定ip为172.25.254.100

NETMASK=255.255.255.0            ##子网掩码为255.255.255.0

PREFIX=24                ##子网掩码为255.255.255.0

####################网关gateway##################

网关就是路由器上和我们的主机处在同一个网段上的ip

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

GATEWAY=网关地址

####################域名解析####################

1.ip映射文件

/etc/hosts

ip    主机名称

2.dns服务器的指向文件

vim /etc/resolv.conf

nameserver 172.25.254.254

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

DNS1=172.25.254.254

PEERDNS=yes|no        ###配置文件是否会修改/etc/resolv.conf no表示不修改

nmcli device show

nmcli device status

nmcli device disconnect eth0

nmcli device connect eth0

nmcli connection edit "System westos1"

nmcli connection modify "System westos1"  ipv4.addresses 172.25.254.101/24

nmcli connection modify "System westos1"  ipv4.dns 172.25.254.1

nmcli connection modify  "System westos1" ipv4.method auto

nmcli connection modify "System westos1" ipv4.method manual

nmcli connection delete "System westos1"

nmcli connection add con-name eth0 ifname eth0  type ethernet ip4 172.25.254.100 gw4 172.25.254.254

nmcli connection modify eth0 ipv4.dns 172.25.254.254
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: