1 安装虚拟机
1、安装虚拟机模拟软件virtualboxhttps://download.virtualbox.org/virtualboxhttps://download.virtualbox.org/virtualbox/7.0.10/VirtualBox-7.0.10-158379-Win.exe
2、在virtualbox中安装虚拟机ubuntu 20.04.6 LTS 桌面版https://www.releases.ubuntu.com/focalhttps://www.releases.ubuntu.com/focal/ubuntu-20.04.6-desktop-amd64.iso
3、安装虚拟机时推荐参数设置:
- 共享粘贴板为双向
- 磁盘大小50GB
- 内存大小为8192MB
- 处理器核心数为4
- 运行峰值100%
- 显存大小128MB
- 存储属性选中固态驱动器
- 网络为桥接网卡
- 启用USB控制器
4、启动ubuntu,安装增强工具,重启,看粘贴是否生效
5、若Ctrl+T无法打开终端,将Settings -> Region & Language -> Language改为Chinese,然后重启,然后再改回English(United States)
2 给当前用户配置sudo权限
1、输入su切换到root,输入root密码
su root
2、打开sudo权限配置文件
visudo
3、修改sudo权限配置文件,假设用户名为shan
在# Allow members of group sudo to execute any command下增加一行
shan ALL=(ALL:ALL) ALL
4、切换回普通用户,假如用户名为shan
su shan
3 更新软件源
备份设置软件源的文件
sudo mv /etc/apt/sources.list /etc/apt/sources_back.list
重新设置软件源的文件内容
sudo nano /etc/apt/sources.list
设置内容如下
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://cn.archive.ubuntu.com/ubuntu focal main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu focal main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://cn.archive.ubuntu.com/ubuntu focal-updates main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu focal-updates main restricted
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://cn.archive.ubuntu.com/ubuntu focal universe
# deb-src http://cn.archive.ubuntu.com/ubuntu focal universe
deb http://cn.archive.ubuntu.com/ubuntu focal-updates universe
# deb-src http://cn.archive.ubuntu.com/ubuntu focal-updates universe
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://cn.archive.ubuntu.com/ubuntu focal multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu focal multiverse
deb http://cn.archive.ubuntu.com/ubuntu focal-updates multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu focal-updates multiverse
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://cn.archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse
## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu focal partner
# deb-src http://archive.canonical.com/ubuntu focal partner
deb http://cn.archive.ubuntu.com/ubuntu focal-security main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu focal-security main restricted
deb http://cn.archive.ubuntu.com/ubuntu focal-security universe
# deb-src http://cn.archive.ubuntu.com/ubuntu focal-security universe
deb http://cn.archive.ubuntu.com/ubuntu focal-security multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu focal-security multiverse
# deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable
# deb-src [arch=amd64] https://download.docker.com/linux/ubuntu focal stable
deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu focal stable
# deb-src [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu focal stable
更新软件源
sudo apt-get update && sudo apt-get upgrade
若提示如下
Get:1 https://mirrors.aliyun.com/docker-ce/linux/ubuntu focal InRelease [57.7 kB]
Err:1 https://mirrors.aliyun.com/docker-ce/linux/ubuntu focal InRelease
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8
Hit:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal InRelease
Hit:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-updates InRelease
Hit:4 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-backports InRelease
Hit:5 http://mirrors.tuna.tsinghua.edu.cn/ubuntu focal-security InRelease
Reading package lists... Done
W: GPG error: https://mirrors.aliyun.com/docker-ce/linux/ubuntu focal InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8
E: The repository 'https://mirrors.aliyun.com/docker-ce/linux/ubuntu focal InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
注意NO_PUBKEY 7EA0A9C3F273FCD8,说明docker存储库没有导入秘钥
运行以下命令即可,注意最后一串数字,替换成实际提示的数字
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7EA0A9C3F273FCD8
4 设置samba服务器
1、安装samba
sudo apt-get update
sudo apt-get install samba samba-common net-tools
2、创建用于映射的文件夹,假设用于共享的文件夹为/project,设置权限为可读可写可执行
sudo mkdir -p /project
sudo chmod -R 777 /project
3、设置用户的samba访问密码,假设用户名为shan
sudo smbpasswd -a shan
输入两次密码后设置成功
4、修改samba的配置文件
sudo nano /etc/samba/smb.conf
假设设置共享文件夹路径为/project,用户为shan,访问文件夹为smb
在文件最后粘贴内容如下:
[smb]
comment = smb folder
browseable = yes
path = /project
create mask = 0700
directory mask = 0700
valid users = shan
force user = shan
force group = shan
public = yes
available = yes
writable = yes
5、重启samba服务
sudo service smbd restart
6、查询虚拟机的ip地址
在终端输入ifconfig命令,假设输出ip地址为10.98.18.10
7、访问虚拟机中的共享文件夹
在资源管理器的窗口中输入\\10.98.18.10,即可看到共享的文件夹
或者在电脑图标上右键映射网络驱动器,文件夹选择\\10.98.18.10\smb,
输入samba的用户账号、密码即可看到共享的文件夹/project
5 设置ssh连接
1、安装ssh
sudo apt-get update
sudo apt-get install openssh-server
2、启动ssh服务
sudo service ssh start
3、查询虚拟机的ip地址
在终端输入ifconfig命令,假设输出ip地址为10.98.18.10
4、ssh访问虚拟机
在SecureCRT中通过ssh协议访问虚拟机。Hostname为ip地址,Username为虚拟机的用户名
ssh shan@10.98.18.10
6 安装依赖包
要将另一台ubuntu上安装的相关包在当前ubuntu上部署,执行以下命令
首先先从另一台ubuntu上输出已经安装的依赖包,例如在linux服务器上运行
dpkg --get-selections > installed_packages.txt
然后将该文件的内容全选复制到当前ubuntu上的installed_packages.txt文件中
最后在当前ubuntu上部署相关软件包,执行以下命令
sudo apt-get install $(awk '{print $1}' installed_packages.txt) || true
当然也可以自己在installed_packages.txt文件中编辑添加需要的相关包,例如
vim
gdb
gcc
g++
git
make
cmake
automake
autoconf
build-essential
net-tools
openssh-server
samba
curl
doxygen
libtool
libc6-dev
libssl-dev