【自学成才系列二】multipass 上 ubuntu 安装篇

用户头像
小朱
关注
发布于: 2020 年 07 月 03 日
【自学成才系列二】multipass上ubuntu安装篇

因为正文不能少于50个字,所以你会看到这里会有这么一段啰嗦的话。



查看vm列表

$ multipass list
Name State IPv4 Image
vm01 Running 192.168.64.2 Ubuntu 18.04 LTS






使用multipass登录vm



$ multipass shell vm01
ubuntu@vm01:~$






查看版本



# 内核版本
$ uname -a
Linux vm01 4.15.0-108-generic #109-Ubuntu SMP Fri Jun 19 11:33:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux






# 系统版本法一
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.4 LTS
Release: 18.04
Codename: bionic



# 系统版本法二
$ cat /proc/version
Linux version 4.15.0-108-generic (buildd@lcy01-amd64-013) (gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)) #109-Ubuntu SMP Fri Jun 19 11:33:10 UTC 2020



# 系统版本法三
$ cat /etc/issue
Ubuntu 18.04.4 LTS \n \l






替换镜像源至阿里云



CN区可用镜像列表: http://mirrors.ubuntu.com/CN.txt



$ sudo bash -c "cp /etc/apt/sources.list /etc/apt/sources.list.backup && cat > /etc/apt/sources.list" <<EOF
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
EOF






更新系统(为什么加参数-y,就是不想太多人打扰朕)



$ sudo bash -c "apt-get update -y && apt-get upgrade -y && apt-get autoremove -y"






创建live组和账号,开启live账号sudo无密码(注意外层需用单引号)



$ sudo bash -c 'name="live" \
&& groupadd $name \
&& useradd -s /bin/bash -g $name $name \
&& mkdir -p /home/$name \
&& chown -R $name:$name /home/$name \
&& echo "$name ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers'



为live账号添加ssh免密码登录(注意外层需用单引号)



$ sudo -iu live bash -c 'ssh-keygen -f $HOME/.ssh/id_rsa -t rsa -N ""'
$ sudo -iu live bash -c 'cat >> $HOME/.ssh/authorized_keys && chmod 600 $HOME/.ssh/authorized_keys' <<EOF
ssh-rsa xxxxxxxx
EOF



修改ssh防断线,关闭root登录、ssh账号密码登录



$ sudo sed -ri 's/^#?ClientAliveInterval [0-9]+$/ClientAliveInterval 15/g' /etc/ssh/sshd_config
$ sudo sed -ri 's/^#?ClientAliveCountMax [0-9]+$/ClientAliveCountMax 45/g' /etc/ssh/sshd_config
$ sudo sed -ri 's/^#?UseDNS.*$/UseDNS no/g' /etc/ssh/sshd_config
$ sudo sed -ri 's/^#?PermitRootLogin.*$/PermitRootLogin no/g' /etc/ssh/sshd_config
$ sudo sed -ri 's/^#?PasswordAuthentication.*$/PasswordAuthentication no/g' /etc/ssh/sshd_config
$ sudo /etc/init.d/ssh restart



为live账号添加各种别名



$ sudo -iu live bash -c 'cat >> /home/live/.bash_profile' <<EOF
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
EOF
$ sudo -iu live bash -c 'cat >> /home/live/.bash_aliases' <<EOF
alias ..='cd ..'
alias ...='cd ../..'
alias cp='cp -i'
alias l='ls -Glah --color=auto'
alias ll='ls -Glah'
alias lt='ls -Glaht'
alias lh='ls -Glah'
alias mv='mv -i'
alias rm='rm -i'
alias tf='tail -f '
alias psg='ps aux|grep'
alias hg='history|grep'
EOF



在本机添加别名快速ssh登录虚拟机vm01(在本机shell执行)



# 找到vm01的ip地址
$ multipass list
Name State IPv4 Image
vm01 Running 192.168.64.2 Ubuntu 18.04 LTS
# 添加alias别名
$ echo "alias vm01='ssh live@192.168.64.2'" >> ~/.bash_aliases
# 立即生效(否则需要重新开shell窗口)
$ source ~/.bash_profile



发布于: 2020 年 07 月 03 日 阅读数: 92
用户头像

小朱

关注

码上失业 2020.06.30 加入

IT混子

评论

发布
暂无评论
【自学成才系列二】multipass上ubuntu安装篇