19 Linux之Python定制篇-apt软件管理和远程登录

19 Linux之Python定制篇-apt软件管理和远程登录

文章目录

  • 19 Linux之Python定制篇-apt软件管理和远程登录
    • 19.1 apt软件管理
      • 19.1.1 apt介绍
      • 19.1.2 更新软件下载地址-阿里源
      • 19.1.3 使用apt完成安装和卸载vim
    • 19.2 远程登录Ubuntu

  • 学习视频来自于B站【小白入门 通俗易懂】2021韩顺平 一周学会Linux。
  • 可能会用到的资料有如下所示,下载链接见文末:
  1. 《鸟哥的Linux私房菜 基础学习篇 第四版》1
  2. 《鸟哥的Linux私房菜 服务器架设篇 第三版》2
  3. 《韩顺平_2021图解Linux全面升级》3

19.1 apt软件管理

19.1.1 apt介绍

  apt是Advanced Packaging Tool的简称,是一款应用在Ubuntu、Debian和相关Linux发行版上安装包管理工具。在Ubuntu下,我们可以使用apt命令很方便的进行软件包的安装、删除、清理等,类似于Windows中的软件管理工具(如“360软件管家”)。比如下面给出了Ubuntu下 apt软件操作相关指令 (带*号的都是重点):

# 带*号的是重点
sudo apt-get update                       #*更新源
sudo apt-get install package              #*安装包
sudo apt-get remove package               #*删除包sudo apt-cache search package             # 搜索软件包
sudo apt-cache show package               #*获取包的相关信息,如说明、大小、版本等
sudo apt-get install package --reinstall  # 重新安装包sudo apt-get -f install                   # 修复安装
sudo apt-get remove package --purge       # 删除包,包括配置文件等
sudo apt-get build-dep package            # 安装相关的编译环境sudo apt-get upgrade                      # 更新已安装的包
sudo apt-get dist-upgrade                 # 升级系统
sudo apt-cache depends package            # 了解使用该包依赖那些包
sudo apt-cache rdepends package           # 查看该包被哪些包依赖
sudo apt-get source package               #*下载该包的源代码

比如现在我们要安装Vim编辑器,只需输入下面的一行代码就可以一键完成了:

sudo apt-get install vim

但是不出意外的话,在没有更新软件下载地址的情况下,大部分人此时肯定会下载失败或者下载巨慢,下一节就来解释为什么。

19.1.2 更新软件下载地址-阿里源

  上一小节提到,在没有更新软件下载地址的情况下,大部分人使用apt下载软件是常常会下载失败或者下载巨慢,这是因为Ubuntu预装的软件下载地址(/etc/apt/sources.list)存储的都是美国的APT服务器地址。这个“APT服务器地址”可以理解成下载软件的地方,比如Android手机上可以下载软件的“应用商店”、ios手机上可以下载软件的“AppStore”。那这个“应用商店”在美国,在国内使用Ubuntu访问肯定会极其不稳定啦。

  为了解决这个问题、方便广大Linux开发者,国内很多大公司&高校,就将美国APT服务器的东西全部搬到自己的网页上,做成镜像网站,也就相当于国内的“应用商店”。此时只需要将Ubuntu默认存储的软件下载地址切换成国内的镜像源网址,就可以很方便的实现软件的安装了,如下图所示。

互联网
连接稳定
定期更新
连接不稳定,不推荐
国内APT的镜像网站
清华大学
阿里云
腾讯云
...
境外的APT服务器(美国)
Ubantu系统
/etc/apt/sources.list:存储软件下载地址
网关
图19-1 APT软件管理示意图

下面列出一些常见的镜像源地址:

  • 阿里云:https://developer.aliyun.com/mirror
  • 清华大学:https://mirrors.tuna.tsinghua.edu.cn/

注:更多国内的镜像源可以参考CSDN博文“国内镜像网站列表”。

吐槽:我刚安装好Ubuntu的时候,没更新源,倒霉催的啥也装不上(比如Vim)。结果按照老韩说的一步步来更新源吧,最后到复制地址到文件的时候,居!然!不!能!复!制!查了一下大概是虚拟机和Windows主机不共享剪贴板,解决了一圈没解决。我想这直接虚拟机上网复制不就好了,结果不知道为啥虚拟机又不能上网了😭。TND,我只好删除再重新安装Ubuntu虚拟机,好在可以虚拟机可以复制粘贴主机上的内容了。这一把我啥也不敢耽误,直接去更新老韩说的“清华大学镜像源”,TND的更新源的时候总是失败😭😭。最后没办法我换了阿里源,才终于更新好了😢。所以下面我演示的是更新阿里源。

打开镜像源网站后,找到Ubuntu对应的连接(网页搜索ctrl+f更快搜索),就可以找到对应的镜像地址了,如下图所示。注意一定要复制对应版本的镜像源,比如Ubuntu20.04.3就复制阿里源20.04(focal)镜像源

图19-2 清华大学的Ubuntu20.04.1镜像源
图19-3 阿里云的Ubuntu20.04.1镜像源

现在就演示如何将/etc/apt/sources.list文件中的美国服务器地址全改成阿里云的镜像源地址:

# 指令速览
# 1. 备份原来的镜像源地址文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup# 2. 清空当前的镜像源文件
echo '' > /etc/apt/sources.list# 3. 将阿里源的内容复制到镜像源文件中
vi sources.list
################################################################
# 打开后进入vi编辑器,不熟悉的同学可以百度“vi编辑器”自行了解一下。
按i键		进入编辑模式
鼠标复制网站上的镜像源内容,然后用鼠标右键粘贴到文件中。
按下esc键
输入:wq		意为保存并退出
################################################################# 4. 告诉系统更新源
sudo apt-get update

下面是实际的终端演示:

# 1. 为了方便,切换成root用户,并切换到/etc/apt目录
lyl@ubuntu:~/Desktop$ su root
Password: 
root@ubuntu:/home/lyl/Desktop# cd /etc/apt# 2. 备份原来的镜像源地址文件
root@ubuntu:/etc/apt# ls
apt.conf.d   preferences.d  sources.list    trusted.gpg.d
auth.conf.d  sources.bak    sources.list.d
root@ubuntu:/etc/apt# cp sources.list sources.list.backup
root@ubuntu:/etc/apt# ls
apt.conf.d   preferences.d  sources.list         sources.list.d
auth.conf.d  sources.bak    sources.list.backup  trusted.gpg.d# 3. 清空当前的镜像源文件
root@ubuntu:/etc/apt# echo '' > sources.list# 4. 将阿里源的内容复制到镜像源文件中
root@ubuntu:/etc/apt# vi sources.list
################################################################
# 打开后进入vi编辑器,不熟悉的同学可以百度“vi编辑器”自行了解一下。
# 使用vi是假设之前网不好,没装上vim
按i键	        进入编辑模式
鼠标复制网站上的镜像源内容,然后用鼠标右键粘贴到文件中。
按下esc键
输入:wq          意为保存并退出
################################################################# 5. 告诉系统更新源
root@ubuntu:/etc/apt# sudo apt-get update
Get:1 https://mirrors.aliyun.com/ubuntu focal InRelease [265 kB]
Get:2 https://mirrors.aliyun.com/ubuntu focal-security InRelease [114 kB]
Get:3 https://mirrors.aliyun.com/ubuntu focal-updates InRelease [114 kB]
Get:4 https://mirrors.aliyun.com/ubuntu focal-backports InRelease [108 kB]
Get:5 https://mirrors.aliyun.com/ubuntu focal/universe Sources [9,707 kB]
Get:6 https://mirrors.aliyun.com/ubuntu focal/restricted Sources [6,472 B]
Get:7 https://mirrors.aliyun.com/ubuntu focal/main Sources [847 kB]
Get:8 https://mirrors.aliyun.com/ubuntu focal/multiverse Sources [174 kB]
Get:9 https://mirrors.aliyun.com/ubuntu focal/main i386 Packages [718 kB]
Get:10 https://mirrors.aliyun.com/ubuntu focal/main amd64 Packages [970 kB]
Get:11 https://mirrors.aliyun.com/ubuntu focal/main Translation-en [506 kB]
Get:12 https://mirrors.aliyun.com/ubuntu focal/main amd64 DEP-11 Metadata [494 kB]
Get:13 https://mirrors.aliyun.com/ubuntu focal/main DEP-11 48x48 Icons [98.4 kB]
Get:14 https://mirrors.aliyun.com/ubuntu focal/main DEP-11 64x64 Icons [163 kB]
Get:15 https://mirrors.aliyun.com/ubuntu focal/main DEP-11 64x64@2 Icons [15.8 kB]
Get:16 https://mirrors.aliyun.com/ubuntu focal/main amd64 c-n-f Metadata [29.5 kB]
Get:17 https://mirrors.aliyun.com/ubuntu focal/restricted i386 Packages [8,112 B]
Get:18 https://mirrors.aliyun.com/ubuntu focal/restricted amd64 Packages [22.0 kB]
Get:19 https://mirrors.aliyun.com/ubuntu focal/restricted Translation-en [6,212 B]
Get:20 https://mirrors.aliyun.com/ubuntu focal/restricted amd64 c-n-f Metadata [392 B]
Get:21 https://mirrors.aliyun.com/ubuntu focal/universe i386 Packages [4,642 kB]
Get:22 https://mirrors.aliyun.com/ubuntu focal/universe amd64 Packages [8,628 kB]
Get:23 https://mirrors.aliyun.com/ubuntu focal/universe Translation-en [5,124 kB]
Get:24 https://mirrors.aliyun.com/ubuntu focal/universe amd64 DEP-11 Metadata [3,603 kB]
Get:25 https://mirrors.aliyun.com/ubuntu focal/universe DEP-11 48x48 Icons [3,016 kB]                 
Get:26 https://mirrors.aliyun.com/ubuntu focal/universe DEP-11 64x64 Icons [7,794 kB]                 
Get:27 https://mirrors.aliyun.com/ubuntu focal/universe DEP-11 64x64@2 Icons [44.3 kB]                
Get:28 https://mirrors.aliyun.com/ubuntu focal/universe amd64 c-n-f Metadata [265 kB]                 
Get:29 https://mirrors.aliyun.com/ubuntu focal/multiverse amd64 Packages [144 kB]                     
Get:30 https://mirrors.aliyun.com/ubuntu focal/multiverse i386 Packages [74.7 kB]                     
Get:31 https://mirrors.aliyun.com/ubuntu focal/multiverse Translation-en [104 kB]                     
Get:32 https://mirrors.aliyun.com/ubuntu focal/multiverse amd64 DEP-11 Metadata [48.4 kB]             
Get:33 https://mirrors.aliyun.com/ubuntu focal/multiverse DEP-11 48x48 Icons [23.1 kB]                
Get:34 https://mirrors.aliyun.com/ubuntu focal/multiverse DEP-11 64x64 Icons [192 kB]                 
Get:35 https://mirrors.aliyun.com/ubuntu focal/multiverse DEP-11 64x64@2 Icons [214 B]                
Get:36 https://mirrors.aliyun.com/ubuntu focal/multiverse amd64 c-n-f Metadata [9,136 B]              
Get:37 https://mirrors.aliyun.com/ubuntu focal-security/main Sources [289 kB]                         
Get:38 https://mirrors.aliyun.com/ubuntu focal-security/universe Sources [192 kB]                     
Get:39 https://mirrors.aliyun.com/ubuntu focal-security/restricted Sources [54.1 kB]                  
Get:40 https://mirrors.aliyun.com/ubuntu focal-security/multiverse Sources [13.8 kB]                  
Get:41 https://mirrors.aliyun.com/ubuntu focal-security/main amd64 Packages [2,362 kB]                
Get:42 https://mirrors.aliyun.com/ubuntu focal-security/main i386 Packages [632 kB]                   
Get:43 https://mirrors.aliyun.com/ubuntu focal-security/main Translation-en [373 kB]                  
Get:44 https://mirrors.aliyun.com/ubuntu focal-security/main amd64 DEP-11 Metadata [59.9 kB]          
Get:45 https://mirrors.aliyun.com/ubuntu focal-security/main DEP-11 48x48 Icons [18.9 kB]             
Get:46 https://mirrors.aliyun.com/ubuntu focal-security/main DEP-11 64x64 Icons [36.0 kB]             
Get:47 https://mirrors.aliyun.com/ubuntu focal-security/main DEP-11 64x64@2 Icons [29 B]              
Get:48 https://mirrors.aliyun.com/ubuntu focal-security/main amd64 c-n-f Metadata [13.0 kB]           
Get:49 https://mirrors.aliyun.com/ubuntu focal-security/restricted amd64 Packages [2,070 kB]          
Get:50 https://mirrors.aliyun.com/ubuntu focal-security/restricted i386 Packages [32.3 kB]            
Get:51 https://mirrors.aliyun.com/ubuntu focal-security/restricted Translation-en [289 kB]            
Get:52 https://mirrors.aliyun.com/ubuntu focal-security/restricted amd64 c-n-f Metadata [580 B]       
Get:53 https://mirrors.aliyun.com/ubuntu focal-security/universe i386 Packages [611 kB]               
Get:54 https://mirrors.aliyun.com/ubuntu focal-security/universe amd64 Packages [872 kB]              
Get:55 https://mirrors.aliyun.com/ubuntu focal-security/universe Translation-en [183 kB]              
Get:56 https://mirrors.aliyun.com/ubuntu focal-security/universe amd64 DEP-11 Metadata [96.3 kB]      
Get:57 https://mirrors.aliyun.com/ubuntu focal-security/universe DEP-11 48x48 Icons [52.0 kB]         
Get:58 https://mirrors.aliyun.com/ubuntu focal-security/universe DEP-11 64x64 Icons [101 kB]          
Get:59 https://mirrors.aliyun.com/ubuntu focal-security/universe DEP-11 64x64@2 Icons [29 B]          
Get:60 https://mirrors.aliyun.com/ubuntu focal-security/universe amd64 c-n-f Metadata [19.0 kB]       
Get:61 https://mirrors.aliyun.com/ubuntu focal-security/multiverse amd64 Packages [23.6 kB]           
Get:62 https://mirrors.aliyun.com/ubuntu focal-security/multiverse i386 Packages [7,196 B]            
Get:63 https://mirrors.aliyun.com/ubuntu focal-security/multiverse Translation-en [5,504 B]           
Get:64 https://mirrors.aliyun.com/ubuntu focal-security/multiverse amd64 DEP-11 Metadata [940 B]      
Get:65 https://mirrors.aliyun.com/ubuntu focal-security/multiverse DEP-11 48x48 Icons [1,867 B]       
Get:66 https://mirrors.aliyun.com/ubuntu focal-security/multiverse DEP-11 64x64 Icons [2,497 B]       
Get:67 https://mirrors.aliyun.com/ubuntu focal-security/multiverse DEP-11 64x64@2 Icons [29 B]        
Get:68 https://mirrors.aliyun.com/ubuntu focal-security/multiverse amd64 c-n-f Metadata [548 B]       
Get:69 https://mirrors.aliyun.com/ubuntu focal-updates/restricted Sources [54.2 kB]                   
Get:70 https://mirrors.aliyun.com/ubuntu focal-updates/main Sources [571 kB]                          
Get:71 https://mirrors.aliyun.com/ubuntu focal-updates/universe Sources [342 kB]                      
Get:72 https://mirrors.aliyun.com/ubuntu focal-updates/multiverse Sources [24.4 kB]                   
Get:73 https://mirrors.aliyun.com/ubuntu focal-updates/main i386 Packages [864 kB]                    
Get:74 https://mirrors.aliyun.com/ubuntu focal-updates/main amd64 Packages [2,753 kB]                 
Get:75 https://mirrors.aliyun.com/ubuntu focal-updates/main Translation-en [456 kB]                   
Get:76 https://mirrors.aliyun.com/ubuntu focal-updates/main amd64 DEP-11 Metadata [275 kB]            
Get:77 https://mirrors.aliyun.com/ubuntu focal-updates/main DEP-11 48x48 Icons [60.8 kB]              
Get:78 https://mirrors.aliyun.com/ubuntu focal-updates/main DEP-11 64x64 Icons [98.3 kB]              
Get:79 https://mirrors.aliyun.com/ubuntu focal-updates/main DEP-11 64x64@2 Icons [29 B]               
Get:80 https://mirrors.aliyun.com/ubuntu focal-updates/main amd64 c-n-f Metadata [17.0 kB]            
Get:81 https://mirrors.aliyun.com/ubuntu focal-updates/restricted i386 Packages [33.7 kB]             
Get:82 https://mirrors.aliyun.com/ubuntu focal-updates/restricted amd64 Packages [2,185 kB]           
Get:83 https://mirrors.aliyun.com/ubuntu focal-updates/restricted Translation-en [306 kB]             
Get:84 https://mirrors.aliyun.com/ubuntu focal-updates/restricted amd64 c-n-f Metadata [576 B]        
Get:85 https://mirrors.aliyun.com/ubuntu focal-updates/universe i386 Packages [744 kB]                
Get:86 https://mirrors.aliyun.com/ubuntu focal-updates/universe amd64 Packages [1,101 kB]             
Get:87 https://mirrors.aliyun.com/ubuntu focal-updates/universe Translation-en [263 kB]               
Get:88 https://mirrors.aliyun.com/ubuntu focal-updates/universe amd64 DEP-11 Metadata [410 kB]        
Get:89 https://mirrors.aliyun.com/ubuntu focal-updates/universe DEP-11 48x48 Icons [280 kB]           
Get:90 https://mirrors.aliyun.com/ubuntu focal-updates/universe DEP-11 64x64 Icons [493 kB]           
Get:91 https://mirrors.aliyun.com/ubuntu focal-updates/universe DEP-11 64x64@2 Icons [29 B]           
Get:92 https://mirrors.aliyun.com/ubuntu focal-updates/universe amd64 c-n-f Metadata [25.5 kB]        
Get:93 https://mirrors.aliyun.com/ubuntu focal-updates/multiverse amd64 Packages [25.8 kB]            
Get:94 https://mirrors.aliyun.com/ubuntu focal-updates/multiverse i386 Packages [8,436 B]             
Get:95 https://mirrors.aliyun.com/ubuntu focal-updates/multiverse Translation-en [7,484 B]            
Get:96 https://mirrors.aliyun.com/ubuntu focal-updates/multiverse amd64 DEP-11 Metadata [940 B]       
Get:97 https://mirrors.aliyun.com/ubuntu focal-updates/multiverse DEP-11 48x48 Icons [1,867 B]        
Get:98 https://mirrors.aliyun.com/ubuntu focal-updates/multiverse DEP-11 64x64 Icons [2,497 B]        
Get:99 https://mirrors.aliyun.com/ubuntu focal-updates/multiverse DEP-11 64x64@2 Icons [29 B]         
Get:100 https://mirrors.aliyun.com/ubuntu focal-updates/multiverse amd64 c-n-f Metadata [620 B]       
Get:101 https://mirrors.aliyun.com/ubuntu focal-backports/main Sources [9,608 B]                      
Get:102 https://mirrors.aliyun.com/ubuntu focal-backports/universe Sources [10.5 kB]                  
Get:103 https://mirrors.aliyun.com/ubuntu focal-backports/main amd64 Packages [45.7 kB]               
Get:104 https://mirrors.aliyun.com/ubuntu focal-backports/main i386 Packages [36.1 kB]                
Get:105 https://mirrors.aliyun.com/ubuntu focal-backports/main Translation-en [16.3 kB]               
Get:106 https://mirrors.aliyun.com/ubuntu focal-backports/main amd64 DEP-11 Metadata [7,968 B]        
Get:107 https://mirrors.aliyun.com/ubuntu focal-backports/main DEP-11 48x48 Icons [7,156 B]           
Get:108 https://mirrors.aliyun.com/ubuntu focal-backports/main DEP-11 64x64 Icons [10.7 kB]           
Get:109 https://mirrors.aliyun.com/ubuntu focal-backports/main DEP-11 64x64@2 Icons [29 B]            
Get:110 https://mirrors.aliyun.com/ubuntu focal-backports/main amd64 c-n-f Metadata [1,420 B]         
Get:111 https://mirrors.aliyun.com/ubuntu focal-backports/restricted amd64 c-n-f Metadata [116 B]     
Get:112 https://mirrors.aliyun.com/ubuntu focal-backports/universe i386 Packages [13.8 kB]            
Get:113 https://mirrors.aliyun.com/ubuntu focal-backports/universe amd64 Packages [25.0 kB]           
Get:114 https://mirrors.aliyun.com/ubuntu focal-backports/universe Translation-en [16.3 kB]           
Get:115 https://mirrors.aliyun.com/ubuntu focal-backports/universe amd64 DEP-11 Metadata [30.5 kB]    
Get:116 https://mirrors.aliyun.com/ubuntu focal-backports/universe DEP-11 48x48 Icons [13.3 kB]       
Get:117 https://mirrors.aliyun.com/ubuntu focal-backports/universe DEP-11 64x64 Icons [22.7 kB]       
Get:118 https://mirrors.aliyun.com/ubuntu focal-backports/universe DEP-11 64x64@2 Icons [29 B]        
Get:119 https://mirrors.aliyun.com/ubuntu focal-backports/universe amd64 c-n-f Metadata [880 B]       
Get:120 https://mirrors.aliyun.com/ubuntu focal-backports/multiverse amd64 c-n-f Metadata [116 B]     
Fetched 68.2 MB in 18s (3,864 kB/s)                                                                   
Reading package lists... Done
# 看到Done就证明更新成功!

19.1.3 使用apt完成安装和卸载vim

  本节以常用的Vim编辑器这款软件为例,演示如何使用apt完成软件的安装、卸载、查询软件信息。下面给出指令速览:

# 1. 安装Vim
sudo apt-get install vim
# 2. 安装Vim完成后,使用Vim创建hello.txt,验证可以正常使用vim指令
vim hello.txt
# 3. 查看Vim的安装信息
sudo apt-cache show vim
# 4. 删除Vim(选做)
sudo apt-get remove vim

下面是实际的终端演示:

# 1. 首先验证没有安装Vim之前,是无法使用Vim指令的
lyl@ubuntu:~/Desktop$ vim hello.txtCommand 'vim' not found, but can be installed with:sudo apt install vim         # version 2:8.1.2269-1ubuntu5.16, or
sudo apt install vim-tiny    # version 2:8.1.2269-1ubuntu5.16
sudo apt install neovim      # version 0.4.3-3
sudo apt install vim-athena  # version 2:8.1.2269-1ubuntu5.16
sudo apt install vim-gtk3    # version 2:8.1.2269-1ubuntu5.16
sudo apt install vim-nox     # version 2:8.1.2269-1ubuntu5.16# 2. 安装Vim
lyl@ubuntu:~/Desktop$ sudo apt-get install vim
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:vim-common vim-runtime vim-tiny
Suggested packages:ctags vim-doc vim-scripts indent
The following NEW packages will be installed:vim vim-runtime
The following packages will be upgraded:vim-common vim-tiny
2 upgraded, 2 newly installed, 0 to remove and 578 not upgraded.
Need to get 7,787 kB of archives.
After this operation, 34.6 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 https://mirrors.aliyun.com/ubuntu focal-security/main amd64 vim-tiny amd64 2:8.1.2269-1ubuntu5.16 [581 kB]
Get:2 https://mirrors.aliyun.com/ubuntu focal-security/main amd64 vim-common all 2:8.1.2269-1ubuntu5.16 [87.2 kB]
Get:3 https://mirrors.aliyun.com/ubuntu focal-security/main amd64 vim-runtime all 2:8.1.2269-1ubuntu5.16 [5,878 kB]
Get:4 https://mirrors.aliyun.com/ubuntu focal-security/main amd64 vim amd64 2:8.1.2269-1ubuntu5.16 [1,241 kB]
Fetched 7,787 kB in 1s (8,606 kB/s)
(Reading database ... 156930 files and directories currently installed.)
Preparing to unpack .../vim-tiny_2%3a8.1.2269-1ubuntu5.16_amd64.deb ...
Unpacking vim-tiny (2:8.1.2269-1ubuntu5.16) over (2:8.1.2269-1ubuntu5) ...
Preparing to unpack .../vim-common_2%3a8.1.2269-1ubuntu5.16_all.deb ...
Unpacking vim-common (2:8.1.2269-1ubuntu5.16) over (2:8.1.2269-1ubuntu5) ...
Selecting previously unselected package vim-runtime.
Preparing to unpack .../vim-runtime_2%3a8.1.2269-1ubuntu5.16_all.deb ...
Adding 'diversion of /usr/share/vim/vim81/doc/help.txt to /usr/share/vim/vim81/doc/help.txt.vim-tiny by vim-runtime'
Adding 'diversion of /usr/share/vim/vim81/doc/tags to /usr/share/vim/vim81/doc/tags.vim-tiny by vim-runtime'
Unpacking vim-runtime (2:8.1.2269-1ubuntu5.16) ...
Selecting previously unselected package vim.
Preparing to unpack .../vim_2%3a8.1.2269-1ubuntu5.16_amd64.deb ...
Unpacking vim (2:8.1.2269-1ubuntu5.16) ...
Setting up vim-common (2:8.1.2269-1ubuntu5.16) ...
Setting up vim-runtime (2:8.1.2269-1ubuntu5.16) ...
Setting up vim (2:8.1.2269-1ubuntu5.16) ...
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vim (vim) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vimdiff (vimdiff) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rvim (rvim) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rview (rview) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vi (vi) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/view (view) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/ex (ex) in auto mode
Setting up vim-tiny (2:8.1.2269-1ubuntu5.16) ...
Processing triggers for desktop-file-utils (0.24-1ubuntu3) ...
Processing triggers for mime-support (3.64ubuntu1) ...
Processing triggers for hicolor-icon-theme (0.17-2) ...
Processing triggers for gnome-menus (3.36.0-1ubuntu1) ...
Processing triggers for man-db (2.9.1-1) ...# 3. 安装Vim完成后,使用Vim创建hello.txt,并验证
lyl@ubuntu:~/Desktop$ vim hello.txt
###################################
# Vim编辑器写上:hello,vim!
###################################
lyl@ubuntu:~/Desktop$ cat hello.txt
hello,vim!# 4. 还可以查看Vim的安装信息
lyl@ubuntu:~/Desktop$ sudo apt-cache show vim
Package: vim
Architecture: amd64
Version: 2:8.1.2269-1ubuntu5.16
Priority: optional
Section: editors
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian Vim Maintainers <pkg-vim-maintainers@lists.alioth.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 3046
Provides: editor
Depends: vim-common (= 2:8.1.2269-1ubuntu5.16), vim-runtime (= 2:8.1.2269-1ubuntu5.16), libacl1 (>= 2.2.23), libc6 (>= 2.29), libcanberra0 (>= 0.2), libgpm2 (>= 1.20.7), libpython3.8 (>= 3.8.2), libselinux1 (>= 1.32), libtinfo6 (>= 6)
Suggests: ctags, vim-doc, vim-scripts
Filename: pool/main/v/vim/vim_8.1.2269-1ubuntu5.16_amd64.deb
Size: 1240908
MD5sum: ab9e41ee56638f5fd750f15cafaffcec
SHA1: 52dd1e72a54c753b1520e5dda3b5f83df84e5d91
SHA256: 699c0a3e7931022b68f7e805ad53cbfd49b135a86fd8dd94d737a539c99f2477
SHA512: dfa74ddca1ca1e46306c946f0025bb657e9edce773caea90816720d3c5c10fd83c65fcdd39e3a6931accccf5a2a4d288ba41f014763bd15a9d558d41896b809d
Homepage: https://www.vim.org/
Description-en: Vi IMproved - enhanced vi editorVim is an almost compatible version of the UNIX editor Vi..Many new features have been added: multi level undo, syntaxhighlighting, command line history, on-line help, filenamecompletion, block operations, folding, Unicode support, etc..This package contains a version of vim compiled with a ratherstandard set of features.  This package does not provide a GUIversion of Vim.  See the other vim-* packages if you need more(or less).
Description-md5: 59e8b8f7757db8b53566d5d119872de8
Task: server, cloud-image, lubuntu-desktop

注:安装过程中可以体会到,因为使用了镜像网站,软件下载速度很快。

19.2 远程登录Ubuntu

  那一般进行软件开发时,肯定是用自己的电脑最习惯,而不是直接在Ubuntu上敲代码,所以Ubuntu的最后一节来讲讲如何远程登录Ubuntu。和CentOS自带远程登录服务不同,Ubuntu上默认没有安装“SSH服务”,所以使用Putty或Xshell等工具远程连接Ubuntu时,会遇到拒绝连接服务。SSH为Secure Shell的缩写,由IETF的网络工作小组(Network Working Group)所制定,是一种建立在应用层和传输层基础上的安全协议。SSH是目前较可靠,专为远程登录会话和其他网络服务提供安全性的协议,几乎所有UNIX/Linux平台都可运行SSH。

Linux系统-UbuntuB
Linux系统-UbuntuA
Windows系统
SSH客户端
(ssh)
端口22
SSH服务器端
(sshd)
SSH客户端
如Xshell6
图19-3 SSH远程登录示意图

  严格来说,使用SSH服务,需要安装相应的“服务器端(sshd)”和“客户端(ssh)”。也就是说,如果A机器想被B机器远程控制,那么A机器需要安装SSH服务器端,B机器需要安装SSH客户端。比如上图所示情况,Windows系统和UbuntuB都想要访问UbuntuA,那么Windiws和UbuntuB就需要安装SSH客户端,而被访问的UbuntuA就需要安装SSH服务端。但通常Ubuntu系统的SSH的安装指令会同时将“服务端”和“客户端”都安装好

sudo apt-get install openssh-server

演示1:查看Ubuntu默认没有安装SSHD服务
下面演示Ubuntu默认没有安装SSHD服务,我们不能进行远程登录。指令速览:

# 1. 先安装netstat指令
lyl@ubuntu:~/Desktop$ sudo apt install net-tools
[sudo] password for lyl: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:net-tools
0 upgraded, 1 newly installed, 0 to remove and 578 not upgraded.
Need to get 196 kB of archives.
After this operation, 864 kB of additional disk space will be used.
Get:1 https://mirrors.aliyun.com/ubuntu focal/main amd64 net-tools amd64 1.60+git20180626.aebd88e-1ubuntu1 [196 kB]
Fetched 196 kB in 0s (685 kB/s)   
Selecting previously unselected package net-tools.
(Reading database ... 158766 files and directories currently installed.)
Preparing to unpack .../net-tools_1.60+git20180626.aebd88e-1ubuntu1_amd64.deb ...
Unpacking net-tools (1.60+git20180626.aebd88e-1ubuntu1) ...
Setting up net-tools (1.60+git20180626.aebd88e-1ubuntu1) ...
Processing triggers for man-db (2.9.1-1) ...# 2. 查看处于LISTEN状态的端口
# 可以看到下面处于LISTEN状态的端口并没有22端口,说明Ubuntu默认并没有SSHD服务监听。
lyl@ubuntu:~/Desktop$ netstat -anp | more
(Not all processes could be identified, non-owned process infowill not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       
PID/Program name    
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      
-                   
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      
-                   
tcp        0      0 192.168.204.129:35502   27.22.57.186:443        TIME_WAIT   
-                   
tcp6       0      0 ::1:631                 :::*                    LISTEN      
-                   
udp        0      0 0.0.0.0:60691           0.0.0.0:*                           
-                   
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           
-                   
udp        0      0 127.0.0.53:53           0.0.0.0:*                           
-                   
udp        0      0 192.168.204.129:68      192.168.204.254:67      ESTABLISHED 
-                   
udp        0      0 0.0.0.0:631             0.0.0.0:*                           
-                   
udp6       0      0 :::5353                 :::*                                
-   

演示2:Ubuntu安装SSH服务并启用

下面就需要安装SSH服务并启用,指令速览:

# 1. 安装SSH服务
sudo apt-get install openssh-server
# 2. 启动sshd服务(会监听端口22)
service sshd restart

注意上面安装SSH服务的指令会在当前Linux上同时安装SSH服务端和客户端,而不只是服务端(server)!

下面是实际的终端演示:

# 实机演示
sudo apt-get install openssh-server
service sshd restart
netstat -anp | more
# 1. 安装SSH服务
lyl@ubuntu:~/Desktop$ sudo apt-get install openssh-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:ncurses-term openssh-client openssh-sftp-server ssh-import-id
Suggested packages:keychain libpam-ssh monkeysphere ssh-askpass molly-guard
The following NEW packages will be installed:ncurses-term openssh-server openssh-sftp-server ssh-import-id
The following packages will be upgraded:openssh-client
1 upgraded, 4 newly installed, 0 to remove and 577 not upgraded.
Need to get 1,360 kB of archives.
After this operation, 6,019 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 https://mirrors.aliyun.com/ubuntu focal-security/main amd64 openssh-client amd64 1:8.2p1-4ubuntu0.9 [671 kB]
Get:2 https://mirrors.aliyun.com/ubuntu focal-security/main amd64 ncurses-term all 6.2-0ubuntu2.1 [249 kB]
Get:3 https://mirrors.aliyun.com/ubuntu focal-security/main amd64 openssh-sftp-server amd64 1:8.2p1-4ubuntu0.9 [51.7 kB]
Get:4 https://mirrors.aliyun.com/ubuntu focal-security/main amd64 openssh-server amd64 1:8.2p1-4ubuntu0.9 [377 kB]
Get:5 https://mirrors.aliyun.com/ubuntu focal/main amd64 ssh-import-id all 5.10-0ubuntu1 [10.0 kB]
Fetched 1,360 kB in 1s (2,091 kB/s)       
Preconfiguring packages ...
(Reading database ... 158815 files and directories currently installed.)
Preparing to unpack .../openssh-client_1%3a8.2p1-4ubuntu0.9_amd64.deb ...
Unpacking openssh-client (1:8.2p1-4ubuntu0.9) over (1:8.2p1-4ubuntu0.1) ...
Selecting previously unselected package ncurses-term.
Preparing to unpack .../ncurses-term_6.2-0ubuntu2.1_all.deb ...
Unpacking ncurses-term (6.2-0ubuntu2.1) ...
Selecting previously unselected package openssh-sftp-server.
Preparing to unpack .../openssh-sftp-server_1%3a8.2p1-4ubuntu0.9_amd64.deb ...
Unpacking openssh-sftp-server (1:8.2p1-4ubuntu0.9) ...
Selecting previously unselected package openssh-server.
Preparing to unpack .../openssh-server_1%3a8.2p1-4ubuntu0.9_amd64.deb ...
Unpacking openssh-server (1:8.2p1-4ubuntu0.9) ...
Selecting previously unselected package ssh-import-id.
Preparing to unpack .../ssh-import-id_5.10-0ubuntu1_all.deb ...
Unpacking ssh-import-id (5.10-0ubuntu1) ...
Setting up openssh-client (1:8.2p1-4ubuntu0.9) ...
Setting up ssh-import-id (5.10-0ubuntu1) ...
Attempting to convert /etc/ssh/ssh_import_id
Setting up ncurses-term (6.2-0ubuntu2.1) ...
Setting up openssh-sftp-server (1:8.2p1-4ubuntu0.9) ...
Setting up openssh-server (1:8.2p1-4ubuntu0.9) ...Creating config file /etc/ssh/sshd_config with new version
Creating SSH2 RSA key; this may take some time ...
3072 SHA256:Mi2n0nliGPMjuoFm8UhtdM+j49m5MyG6qUQtPidJX/k root@ubuntu (RSA)
Creating SSH2 ECDSA key; this may take some time ...
256 SHA256:BI4Iz6Tkl+/MaqEw1rKuAsBTlKimuFJ5uWKYPbx960s root@ubuntu (ECDSA)
Creating SSH2 ED25519 key; this may take some time ...
256 SHA256:juRN5ixuAQ8H4zJc7ACTntHWte4r15oLtZccbY+6mZU root@ubuntu (ED25519)
Created symlink /etc/systemd/system/sshd.service → /lib/systemd/system/ssh.service.
Created symlink /etc/systemd/system/multi-user.target.wants/ssh.service → /lib/systemd/system/ssh.service.
rescue-ssh.target is a disabled or a static unit, not starting it.
Processing triggers for systemd (245.4-4ubuntu3.2) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for ufw (0.36-6) ...# 2. 启动sshd服务(会监听端口22)
lyl@ubuntu:~/Desktop$ service sshd restart# 3. 查看处于LISTEN状态的端口是否有22
lyl@ubuntu:~/Desktop$ netstat -anp | more
(Not all processes could be identified, non-owned process infowill not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       
PID/Program name    
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      
-                   
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      
-                   
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      
-                   
tcp        0      0 192.168.204.129:58732   27.159.77.240:443       TIME_WAIT   
-                   
tcp6       0      0 ::1:631                 :::*                    LISTEN      
-                   
tcp6       0      0 :::22                   :::*                    LISTEN      # 显然这里有监听
-                   
udp        0      0 0.0.0.0:60691           0.0.0.0:*                           
-                   
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           
-                   
udp        0      0 127.0.0.53:53           0.0.0.0:*                           
-                   
udp        0      0 192.168.204.129:68      192.168.204.254:67      ESTABLISHED 
-     

演示3:远程登录Ubuntu

安装好SSH服务后,就可以远程登录Ubuntu了,共有下面两种情况:

  1. Windows远程登录UbuntuA:和CentOS相同,先在UbuntuA使用ifconfig查看Ubuntu的IP地址,然后在Windows上使用Xshell即可远程登录UbuntuA。
  2. UbuntuB远程登录UbuntuA:在创建服务器集群时,会使用到该技术。UbuntuB只需开启“客户端(ssh)”,无需开启“服务器端(sshd)”。基本语法如下:
# 基本语法-ssh登录
ssh 用户名@IP
# 例:ssh Ubuntu@192.168.200.222
# 注:若使用ssh访问出现错误,可查看是否有该文件/.ssh/known_ssh并尝试删除解决,一般不会有问题。# 基本语法-ssh登出(均可)
exit
logout

注:直接复制刚建好的Ubuntu虚拟机文件夹,然后就可以快速得到一个新的Ubuntu系统。但这种情况下两个主机的主机名完全相同,远程登录时可以使用ifconfig查看IP地址可以发现当前登录的账户有所不同。

由于远程登录演示窗口开的有点多,但原理又不复杂,所以下面只给出UbuntuB远程登录UbuntuA的代码速览,而没有实际的终端演示:

# 1. 打开UbuntuA的终端,查看UbuntuA的IP地址,假设为192.168.200.222,主机名为UbuntuA
UbuntuA终端:ifconfig# 2. 打开UbuntuB的终端,查看UbuntuB的IP地址,假设为192.168.200.220
UbuntuB终端:ifconfig# 3. 然后远程登录到UbuntuA
UbuntuB终端:ssh UbuntuA@192.168.200.222# 4. 再次查看IP地址,发现已经变成了UbuntuA的IP,证明远程登录成功
UbuntuB终端:ifconfig

  1. 《鸟哥的Linux私房菜 基础学习篇 第四版》 ↩︎

  2. 《鸟哥的Linux私房菜 服务器架设篇 第三版》 ↩︎

  3. 《韩顺平_2021图解Linux全面升级》 ↩︎

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/65174.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Linux x86_64 C语言实现gdb断点机制

文章目录 前言一、trap指令简介二、调用ptrace三、创建breakpoints四、CONT 和 SINGLESTEP五、完整代码演示六、增加参数检测参考资料 前言 本文参考文章&#xff1a;Implementing breakpoints on x86 Linux 一、trap指令简介 将通过在断点地址向目标进程的内存中插入一条新…

面试中的商业思维:如何展示你对业务的理解

&#x1f337;&#x1f341; 博主猫头虎&#xff08;&#x1f405;&#x1f43e;&#xff09;带您 Go to New World✨&#x1f341; &#x1f984; 博客首页——&#x1f405;&#x1f43e;猫头虎的博客&#x1f390; &#x1f433; 《面试题大全专栏》 &#x1f995; 文章图文…

SourceTree 使用技巧

参考资料 SourceTree使用教程&#xff08;一&#xff09;—克隆、提交、推送SourceTree的软合并、混合合并、强合并区别SourceTree 合并分支上的多个提交&#xff0c;一次性合并分支的多次提交至另一分支&#xff0c;主分支前进时的合并冲突解决 目录 一. 基础设置1.1 用户信息…

VR司法法治教育平台,沉浸式课堂教学培养刑侦思维和能力

VR司法法治教育平台提供了多种沉浸式体验&#xff0c;通过虚拟现实(Virtual Reality&#xff0c;简称VR)技术让用户深度参与和体验法治知识。以下是一些常见的沉浸式体验&#xff1a; 1.罪案重现 VR司法法治教育平台可以通过重现真实案例的方式&#xff0c;让用户亲眼目睹罪案发…

一文了解气象站是什么,作用有哪些?

气象站被广泛应用于气象、农业、交通、能源、水利、环保等领域&#xff0c;是一种用于收集、分析和处理气象数据的设备&#xff0c;能够为人们提供及时、准确的气象数据和决策支持。 气象站一般由传感器、环境监控主机和监控平台组成。传感器能够测量各种气象要素&#xff0c;…

Spring 中存取 Bean 的相关注解

目录 一、五大类注解 1、五大类注解存储Bean对象 1.1Controller(控制器储存) 1.2Service(服务存储) 1.3Repository(仓库存储) 1.4Component(组件存储) 1.5Configuration(配置存储) 2、五大类注解小结 2.1为什么要这么多类注解 2.2 五大类注解之间的关系 二、方法注解 1.方法注…

SQL-子查询

SQL 子查询 是指将一个SELECT查询&#xff08;子查询&#xff09;的结果用括号括起来作为另一个SQL语句的数据来源或者判断条件

【Bug】Ubuntu 有线设置打不开无反应

前言&#xff1a; 突然有线设置就没法启用了&#xff0c;但是能联网&#xff0c;能查看ip 解决&#xff1a; 最后安装了一个新的依赖包&#xff1a; sudo apt install gnome-control-center 然后就可以了 还有一个方法&#xff0c;没试过&#xff0c;但感觉有点道理的&#…

在抖音中使用语聚AI,实现自动回复用户视频评论、私信问答

您可以通过集简云数据流程&#xff0c;将语聚AI助手集成到抖音视频评论、抖音私信&#xff0c;实现自动回复用户视频评论、私信问答&#xff0c;大大提升账号互动与运营效率。 效果如下&#xff1a; 自动化流程&#xff1a; ● 抖音普通号评论对接语聚AI&#xff08;点击可一…

宏观经济和风电预测误差分析(Matlab代码实现)

&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。 ⛳️座右铭&a…

pytorch异常——RuntimeError:Given groups=1, weight of size..., expected of...

文章目录 省流异常报错异常截图异常代码原因解释修正代码执行结果 省流 nn.Conv2d 需要的输入张量格式为 (batch_size, channels, height, width)&#xff0c;但您的示例输入张量 x 是 (batch_size, height, width, channels)。因此&#xff0c;需要对输入张量进行转置。 注意…

LLM学习笔记(1)

学习链接 ChatGPT Prompt Engineering for Developers - DeepLearning.AI 一、prompt engineering for developer 1、原则 prompting principles and iterative pattern 2、用于summarize 环境与helper functions import openai import osfrom dotenv import load_dotenv…

[C++] STL_list常用接口的模拟实现

文章目录 1、list的介绍与使用1.1 list的介绍1.2 list的使用 2、list迭代器3、list的构造4、list常用接口的实现4.1 list capacity4.2 插入删除、交换、清理4.2.1 insert任意位置插入4.2.2 push_front头插4.2.3 push_back尾插4.2.4 erase任意位置删除4.2.5 pop_front头删4.2.6 …

Redis之管道解读

目录 基本介绍 使用例子 管道对比 管道与原生批量命令对比 管道与事务对比 使用pipeline注意事项 基准测试 基本介绍 Redis是一种基于客户端-服务端模型以及请求/响应协议的TCP服务器。 这意味着请求通常按如下步骤处理&#xff1a; 客户端发送一个请求到服务器&am…

java 八股文 基础 每天笔记随机刷

Component 和 PostConstruct 搭配使用 被Component注解标识的类在应用程序启动时会被实例化&#xff0c;并由Spring容器进行管理。PostConstruct是一个Java注解&#xff0c;用于标记一个方法在类被实例化后自动执行。该方法必须是非静态的&#xff0c;没有参数&#xff0c;且不…

数字货币量化交易平台

数字货币量化交易平台是近年来金融科技领域迅速崛起的一种创新型交易方式。它通过应用数学模型和算法策略&#xff0c;实现对数字货币市场的自动交易和风险控制。然而&#xff0c;要在这个竞争激烈的领域中脱颖而出&#xff0c;一个数字货币量化交易平台需要具备足够的专业性&a…

正中优配:A股早盘三大股指微涨 华为概念表现活跃

周三&#xff08;8月30日&#xff09;&#xff0c;到上午收盘&#xff0c;三大股指团体收涨。其间上证指数涨0.06%&#xff0c;报3137.72点&#xff1b;深证成指和创业板指别离涨0.33%、0.12%&#xff1b;沪深两市合计成交额6423.91亿元&#xff0c;总体来看&#xff0c;两市个…

java-数组

数组静态初始化写法&#xff1a; //静态初始化数组 int[] age new int[] {7,18,19}; double[] scores new double[]{67.5,77.8,94.2,99};//静态初始化数组简化写法 int[] age1 {7,18,19}; double[] scores2 {67.5,77.8,94.2,99};数组在内存中定义方式&#xff1a; 1.在内…

opencv的haarcascade_frontalface_default.xml等文件

文章目录 GitHub下载在安装好的OpenCV文件夹下寻找opencv-python中获取 GitHub下载 下载地址&#xff1a;https://github.com/opencv/opencv/tree/master/data/haarcascades 在安装好的OpenCV文件夹下寻找 路径如下&#xff1a; 你安装的opencv路径\OpenCV\opencv\build\et…

ELK安装、部署、调试(一)设计规划及准备

一、整体规划如图&#xff1a; 【filebeat】 需要收集日志的服务器&#xff0c;安装filebeat软件&#xff0c;用于收集日志。logstash也可以收集日志&#xff0c;但是占用的系统资源过大&#xff0c;所以使用了filebeat来收集日志。 【kafka】 接收filebeat的日志&#xff…