1.配置网络目的 1.远程登录它 2.可以使用yum安装其他的包 1.1配置网络步骤
1.执行dhclient命令,自动获取ip地址(NAT模式,它可以自动生成一个ip地址) 查看ip地址的命令ip addr 快捷键ctrl -L 清屏 2.配置ip地址,要知道:ip地址,子网掩码,网关,DNS 查看网关命令iproute 公共的DNS:119.29.29.29 114.114.114.114 202.106.0.20 8.8.8.8 3.编辑配置文件 按Tab键自动补全命令或者文件路径名字 vi /etc/sysconfig/network-scripts/ifcfg-ens33直接回车,进入到配置文件里面按i,进入编辑模式,用方向键把光标挪到最下面,另外一行添加如下内容 IPADDR=192.168.109.133 #自动获取的ip地址 NETMASK=255.255.255.0 #地址 GATEWAY=192.168.109.2 #获取的关网 DNS1=119.29.29.29 #dns 还需要更改BOOTPROTO=static和ONBOOT=yes 获取ip地址,查看ip
root@localhost ~]# dhclient
[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens36: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:e7:4a:fa brd ff:ff:ff:ff:ff:ff
inet 192.168.109.133/24 brd 192.168.109.255 scope global noprefixroute ens36
valid_lft forever preferred_lft forever
inet6 fe80::4949:264b:7529:e05e/64 scope link noprefixroute
valid_lft forever preferred_lft forever
获取网关
[root@localhost ~]# ip route
default via 192.168.109.2 dev ens36 proto dhcp metric 100
192.168.109.0/24 dev ens36 proto kernel scope link src 192.168.109.133 metric 100
编辑配置文件
[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg--ens36
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static #需要更改地方,改为静态
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens36
UUID=78df5c4d-7093-4c7d-a0a0-92dfdff18248
DEVICE=ens36
ONBOOT=yes #更改为yes
IPADDR=192.168.109.133 #获取的ip地址
NETMASK=255.255.255.0 #地址
GATEWAY=192.168.109.2 #获取的关网
DNS1=119.29.29.29 #公共DNS
Esc+Shift+;wq保存退出
重启网络服务,ping百度 [root@localhost ~]# systemctl restart network [root@localhost ~]# ping www.baidu.com PING www.baidu.com (14.215.177.38) 56(84) bytes of data. 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=1 ttl=128 time=16.7 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=2 ttl=128 time=16.5 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=3 ttl=128 time=15.6 ms 64 bytes from 14.215.177.38 (14.215.177.38): icmp_seq=4 ttl=128 time=15.8 ms 其他
cat 查看文件内容 如果遇到一个很长的文件,cat之后就看不到前面的内容了,此时可以用管道和less命令结合起来查看,管道符 | 作用是把管道左边的命令交给管到右边命令去处理 如:cat /etc/init.d/network | less b 网上翻 f往下翻 q退出less 2.远程登录 xshell 登录 远程的linux 还有putty
Xshell个人版下载 试试这个地址能否下载:https://cdn.netsarang.net/0763e317/Xshell-6.0.0121p.exe 如果不行,就到官网(下面地址)下吧 https://www.netsarang.com/download/down_form.html?code=622 说明:License type 选择"Home and school use" putty官方下载地址: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
这边选择的是xshell,可以Windows登录linux linux登录linux mca登录linux
linux登录linux
[root@localhost ~]# ssh root@192.168.109.133 //登录命令 The authenticity of host '192.168.109.133 (192.168.109.133)' can't be established. ECDSA key fingerprint is SHA256:C3899wVB7Svy9IdEn7wPBSAbZCyrHR4nSlOQnf/thlY. ECDSA key fingerprint is MD5:30:f1:03:ae:84:a6:f6:d7:f0:0a:dd:a2:2f:38:0a:d3. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.109.133' (ECDSA) to the list of known hosts. root@192.168.109.133's password: 输入密码 2.0秘钥认证 使用一堆秘钥进行验证身份。公钥+私钥 公钥是用来加密,私钥是用来解密
点击工具找到-用户秘钥管理者-点击生成
保持默认
下一步
输入秘钥名称-点击完成
点击属性-点击公钥一会要用到
想验证那台机器就到那台机器上去配置
把公钥放到哪里是要讲究的
[root@localhost ~]# cd ~/.ssh/ 进入目录 [root@localhost .ssh]# vi authorized_keys 编辑配件文件 把刚刚公钥复制进来 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAmljL8plyVnsd8crXSYfogx6wYtMh3Xj3fkfqgS5LiYxUsqhXYmqOZZ7zpWYHeuKBAXfd/T0gjRQJKwETC/qz0kV9mIwRrW9rDlU/oo/w4afgxTtZlrYZ5mcUpExZnmL/FuccLjkEJfySfMfybTJom85NijgCpzxnvRE6BHUzQZVF+Vo5fMfu/XxSNkLr4UtbaLubsqft8deQxpQzvkzFM+87FdJFeYo+0oMYWS9ifid6DjI/OdRNxJwROMK34qgXzyhJjQpZCqwUDKa1qk1VJ6nrjDwBnSiqc0Lc/N0dldmwMOT1X8m5PYoj1a6MgRkJ/hzAdMd5acy+l1cqQ0zYGQ== rsa 2048-082719 给文件600权限
[root@localhost .ssh]# chmod 600 authorized_keys 回到xshell点击主机名-属性
点击用户身份认证-选择Public Key-在选择用户秘钥的名字-确定即可登录进linux
总结:xshell-工具-用户秘钥管理者-生成-密码留空-复制公钥
到linux机器执行
1.创建.ssh目录 mkdir ~/.ssh
2.进入cd .ssh
3.编辑配置文件vi authorized_keys 注:这配置文件不能打错
4.给文件600权限
5.到xshell的会话属性-用户身份认证-选择Public Key-在选择用户秘钥的名字-确定即可登录进linux
3.0Linux密钥认证登录Linux 到vmware
1.做一个快照 点击右键-找到快照-拍摄快照
2.点击右键-管理-克隆
如何命令关机? 执行命令 init 0 或者shutdown -h now
如何命令重启?执行命令init 6 或者reboot ,shutdown -r now
下一步 虚拟机中的当前状态 连接克隆 填写名称和路径
3.修改网卡ip
编辑vi /etc/sysconfig/network-scripts/ifcfg-ens36
修改IPADDR=的ip
找到UUID哪行前面加上#即可
更改主机名
hostnamectl set-hostname linux1 秘钥认证 [root@linux1 ~]# ssh-keygen 生成秘钥对 Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): /root/.ssh/id_rsa already exists. Overwrite (y/n)? y 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:qk/l/cPbf5wfG2zK9g6GDZrPfR08GPuqTn/oy4eBXIM root@linux1 The key's randomart image is: +---[RSA 2048]----+ | | | | | . | | E + | | S ..o * | | + .oo++.+ | | o .o.+ +=*=| | o +.O=+B| | ... .=%X==| +----[SHA256]-----+
[root@linux1 ~]# ssh-copy-id root@192.168.109.134 拷贝公钥到那台机器上 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" /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.109.134's password: 输入134ip的密码
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.109.134'" and check to make sure that only the key(s) you wanted were added.
[root@linux1 ~]# ssh root@192.168.109.134 登录 Last failed login: Tue Aug 27 10:35:04 CST 2019 from 192.168.109.133 on ssh:notty There was 1 failed login attempt since the last successful login. Last login: Tue Aug 27 10:23:56 2019 from 192.168.109.1 [root@linux2 ~]# 5.0重置root密码 忘记root密码,没办法登录,需要重置密码。
用的是秘钥认证,忘记root密码无所谓。只要你记得秘钥即可。
密码和秘钥都支持远程登录。是不是说启用秘钥,密码就失效 了.不是两者二选一,密钥难被破解
改密码:root用户执行passwd回车输入两次密码即可,root更改普通用户输入passwd+用户名即可 普通用户自己更改也是passwd回车
如果忘记密码和秘钥认证。总之就是无法远程登录了如何做?
单用户
救援模式