VMVare安装Ubuntu18.04

1. 环境准备

  1. 下载镜像
    下载ubuntu-18.04.4-live-server-amd64.iso
    http://mirrors.aliyun.com/ubuntu-releases/18.04/ubuntu-18.04.4-live-server-amd64.iso
  2. 配置虚拟机资源
内存处理器数量处理器核数硬盘
2G2120G
  1. vmvare 选择镜像
    在这里插入图片描述

2.安装

整体按照提示,直接安装即可

STEP1
在这里插入图片描述
STEP2
在这里插入图片描述
STEP3: 此处注意将keyboard相关设置调整为Chinese
在这里插入图片描述
STEP4
在这里插入图片描述
STEP5
在这里插入图片描述
STEP6
在这里插入图片描述
STEP7
在这里插入图片描述
STEP8
在这里插入图片描述
STEP9
在这里插入图片描述
STEP10
在这里插入图片描述
STEP11
在这里插入图片描述
STEP12
在这里插入图片描述
STEP13
在这里插入图片描述
STEP14
在这里插入图片描述
STEP15
在这里插入图片描述

3 基础配置

3.1 root免密设置

dd@ubuntu04:~$ sudo passwd root
[sudo] passwd for dd:
Enter new UNIX password:
Retype new UNIX password:
passwd: password update successfully

3.2 ssh安装

a. 检查ssh
Ubuntu系统默认是没有SSH服务的,故要检查SSH服务是否已安装。
打开终端输入以下指令:

dd@ubuntu04:~$ ps -e | grep ssh
  1796 ?        00:00:00 sshd
  2003 ?        00:00:00 sshd
  2082 ?        00:00:00 sshd
  2215 ?        00:00:00 sshd
  2282 ?        00:00:00 sshd

若输入指令后显示类似于上图所示,则说明SSH服务已启动
其中sshd表示ssh-server已启动,ssh表示ssh-client已启动

b. 安装SSH服务

sudo apt-get install openssh-client
sudo apt-get install openssh-server

c. 启动SSH服务

sudo /etc/init.d/ssh start

启动后通过以下指令判断SSH服务是否正确启动:

ps -e | grep ssh

3.3 修改ip地址

修改前:

dd@ubuntu04:~$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.31.132  netmask 255.255.255.0  broadcast 192.168.31.255
        inet6 fe80::20c:29ff:fed0:84b3  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:d0:84:b3  txqueuelen 1000  (Ethernet)
        RX packets 1270  bytes 789800 (789.8 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 466  bytes 41222 (41.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 105  bytes 8287 (8.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 105  bytes 8287 (8.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

进行修改:

dd@ubuntu04:~$ sudo vim /etc/netplan/50-cloud-init.yaml 
[sudo] password for dd: 
dd@ubuntu04:~$ sudo vim /etc/netplan/50-cloud-init.yaml 
dd@ubuntu04:~$ sudo netplan apply

修改内容:

# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        ens33:
            addresses:
            - 192.168.31.204/24
            gateway4: 192.168.31.2
            nameservers:
                    addresses:
                    - 192.168.31.2
                    search: []
            dhcp4: no
            optional: true

    version: 2

修改之后:

dd@ubuntu04:~$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.31.204  netmask 255.255.255.0  broadcast 192.168.31.255
        inet6 fe80::20c:29ff:fed0:84b3  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:d0:84:b3  txqueuelen 1000  (Ethernet)
        RX packets 2121  bytes 865084 (865.0 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 974  bytes 133551 (133.5 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 105  bytes 8287 (8.2 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 105  bytes 8287 (8.2 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

TIPS:
相信很多人在vim里粘贴带有缩进的内容都会遇到缩进混乱的销魂效果(如下图所示)

这个其实不是什么 bug。而是自动缩进autoindent搞的鬼,那我们也不能关了自动缩进。解决方法如下,在粘贴前输入下面的命令:
:set paste
然后按i切换为输入模式,你会发现最下方显示就会显示:
—INSERT—(paste)
这样你再粘贴的内容就是正常的了。粘贴完成之后记得切换为命令模式输入下面的命令来退出粘贴模式,不然你就会发现自动缩进失效了。
:set nopaste
在这里插入图片描述

3.4 sudo添加

sudo vim /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL
dd      ALL=(ALL:ALL) NOPASSWD:ALL # add
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL
%sudo   ALL=(ALL:ALL) NOPASSWD:ALL # add

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

3.5 ssh免密登录

dd@ubuntu05:~$ sudo vim /etc/hosts

配置hosts

127.0.0.1 localhost
127.0.1.1 ubuntu05
192.168.31.204 ubuntu04
192.168.31.205 ubuntu05
192.168.31.206 ubuntu06

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

生成秘钥

dd@ubuntu05:~$ ssh-keygen 

拷贝秘钥

ssh-copy-id ubuntu05
ssh-copy-id ubuntu06

3.6 scp 配置

scp出现Permission denied (publickey). lost connection
原因:scp是基于ssh的拷贝服务,ssh在没有密钥登录的情况下,禁用了密码登录。想要解决只需要修改配置文件。
登录远程主机,将/etc/ssh/sshd_config文件中的PasswordAuthentication no 改为PasswordAuthentication yes
重启sshd服务

systemctl restart ssh.service

4 参考文献

[1] Ubuntu18.04设置sudo免密码
[2] Ubuntu环境下SSH服务安装、SSH远程登录以及SSH数据传输
[3] Ubuntu 18.04修改IP地址
[4] Ubuntu18.04 首次使用设置 root 密码
[5] Ubuntu18.04 修改IP地址、查看网关、防火墙

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值