2023年8月21日 星期一

Linux Mint在升級後,Docker就無法安裝的解決方法

【前言】

前幾天,我把VM上的Linux Mint從21.1升級到了21.2,然後再來安裝Docker時,Docker就一直出錯,再也裝不起來了。後來解決了,解決方法如下。

【解決過程】

 先來看看情況是怎樣?

cheeren@cheeren-virtual-machine:~$ sudo apt-get update

[sudo] cheeren 的密碼:         

已有:1 http://free.nchc.org.tw/ubuntu jammy InRelease

已有:2 http://free.nchc.org.tw/ubuntu jammy-updates InRelease                  

已有:3 http://free.nchc.org.tw/ubuntu jammy-backports InRelease                

已有:4 https://dl.google.com/linux/chrome/deb stable InRelease                 

略過:5 http://ftp.tku.edu.tw/Linux/LinuxMint/linuxmint victoria InRelease      

已有:6 http://ftp.tku.edu.tw/Linux/LinuxMint/linuxmint victoria Release        

已有:7 http://packages.microsoft.com/repos/code stable InRelease               

已有:8 https://packages.microsoft.com/repos/edge stable InRelease              

已有:9 http://security.ubuntu.com/ubuntu jammy-security InRelease              

正在讀取套件清單... 完成

cheeren@cheeren-virtual-machine:~$ sudo apt-get install \

    ca-certificates \

    curl \

    gnupg \

    lsb-release

正在讀取套件清單... 完成

正在重建相依關係... 完成  

正在讀取狀態資料... 完成  

lsb-release 已是最新版本 (11.1.0ubuntu4)。

ca-certificates 已是最新版本 (20230311ubuntu0.22.04.1)。

curl 已是最新版本 (7.81.0-1ubuntu1.13)。

gnupg 已是最新版本 (2.2.27-3ubuntu2.1)。

升級 0 個,新安裝 0 個,移除 0 個,有 2 個未被升級。

cheeren@cheeren-virtual-machine:~$ sudo mkdir -p /etc/apt/keyrings

cheeren@cheeren-virtual-machine:~$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

檔案 '/etc/apt/keyrings/docker.gpg' 已存在. 是否覆寫?(y/N) y

cheeren@cheeren-virtual-machine:~$ echo \

  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \

  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

cheeren@cheeren-virtual-machine:~$ sudo apt-get update

已有:1 http://free.nchc.org.tw/ubuntu jammy InRelease

已有:2 http://free.nchc.org.tw/ubuntu jammy-updates InRelease                  

已有:3 http://free.nchc.org.tw/ubuntu jammy-backports InRelease                

已有:4 https://dl.google.com/linux/chrome/deb stable InRelease                 

已有:5 http://packages.microsoft.com/repos/code stable InRelease               

略過:6 http://ftp.tku.edu.tw/Linux/LinuxMint/linuxmint victoria InRelease      

已有:7 http://ftp.tku.edu.tw/Linux/LinuxMint/linuxmint victoria Release        

已有:8 https://packages.microsoft.com/repos/edge stable InRelease

已有:9 http://security.ubuntu.com/ubuntu jammy-security InRelease

略過:10 https://download.docker.com/linux/ubuntu victoria InRelease

錯誤:11 https://download.docker.com/linux/ubuntu victoria Release

  404  Not Found [IP: 13.35.35.17 443]

正在讀取套件清單... 完成

E: The repository 'https://download.docker.com/linux/ubuntu victoria Release' does not have a Release file.

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.


這裡出錯了,所以不能更新。不解決這個問題的話是無法繼續安裝的。

先來看看最重要的檔案出了什麼問題?先看看repository哪裡不對。


cheeren@cheeren-virtual-machine:~$ cat /etc/apt/sources.list.d/docker.list 

deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu   victoria stable


沒錯,問題就出在這裡。由於我目前所在的OS的是Linux Mint,而不是Ubuntu。


這裡要說明要如何修改/etc/apt/sources.list.d/docker.list:

首先,看看版本出了什麼問題:


cheeren@cheeren-virtual-machine:~$ cat /etc/os-release | grep -i codename

VERSION_CODENAME=victoria

UBUNTU_CODENAME=jammy


原來是CODENAME的問題!

Linux Mint的CODENAME目前是victoria,而若是對照Ubuntu,Ubuntu目前版本的CODENAME則是jammy。我現在Docker所使用的安裝套件是Ubuntu所用的套件,所以,要把/etc/apt/sources.list.d/docker.list中,所有victoria改成jammy即可。

這裡要注意權限,因為這個檔案只能有ROOT權限才能修改。修改完後請繼續:


cheeren@cheeren-virtual-machine:~$ sudo vi /etc/apt/sources.list.d/docker.list


修改好了之後,重來一次:


cheeren@cheeren-virtual-machine:~$ sudo apt-get update

略過:1 http://ftp.tku.edu.tw/Linux/LinuxMint/linuxmint victoria InRelease

已有:2 http://free.nchc.org.tw/ubuntu jammy InRelease                          

已有:3 https://dl.google.com/linux/chrome/deb stable InRelease                 

已有:4 http://ftp.tku.edu.tw/Linux/LinuxMint/linuxmint victoria Release        

已有:5 http://free.nchc.org.tw/ubuntu jammy-updates InRelease                  

已有:6 http://free.nchc.org.tw/ubuntu jammy-backports InRelease                

下載:7 https://download.docker.com/linux/ubuntu jammy InRelease [48.9 kB]      

已有:8 http://packages.microsoft.com/repos/code stable InRelease               

已有:9 https://packages.microsoft.com/repos/edge stable InRelease              

已有:10 http://security.ubuntu.com/ubuntu jammy-security InRelease  

下載:12 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages [21.4 kB]

取得 70.3 kB 用了 2s (36.8 kB/s)    

正在讀取套件清單... 完成

cheeren@cheeren-virtual-machine:~$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

正在讀取套件清單... 完成

正在重建相依關係... 完成  

正在讀取狀態資料... 完成  

下列的額外套件將被安裝:

  docker-buildx-plugin docker-ce-rootless-extras git git-man liberror-perl

  libslirp0 pigz slirp4netns

建議套件:

  aufs-tools cgroupfs-mount | cgroup-lite git-daemon-run | git-daemon-sysvinit

  git-doc git-email git-gui gitk gitweb git-cvs git-mediawiki git-svn

下列【新】套件將會被安裝:

  containerd.io docker-buildx-plugin docker-ce docker-ce-cli

  docker-ce-rootless-extras docker-compose-plugin git git-man liberror-perl

  libslirp0 pigz slirp4netns

升級 0 個,新安裝 12 個,移除 0 個,有 2 個未被升級。

需要下載 118 MB 的套件檔。

此操作完成之後,會多佔用 435 MB 的磁碟空間。

是否繼續進行 [Y/n]? [Y/n] 


以下略過......


設定 git (1:2.34.1-1ubuntu1.10) ...

執行 man-db (2.10.2-1) 的觸發程式……

執行 libc-bin (2.35-0ubuntu3.1) 的觸發程式……


看看是否安裝成功?


cheeren@cheeren-virtual-machine:~$ docker --version

Docker version 24.0.5, build ced0996


cheeren@cheeren-virtual-machine:~$ sudo docker version

Client: Docker Engine - Community

 Version:           24.0.5

 API version:       1.43

 Go version:        go1.20.6

 Git commit:        ced0996

 Built:             Fri Jul 21 20:35:18 2023

 OS/Arch:           linux/amd64

 Context:           default


Server: Docker Engine - Community

 Engine:

  Version:          24.0.5

  API version:      1.43 (minimum version 1.12)

  Go version:       go1.20.6

  Git commit:       a61e2b4

  Built:            Fri Jul 21 20:35:18 2023

  OS/Arch:          linux/amd64

  Experimental:     false

 containerd:

  Version:          1.6.22

  GitCommit:        8165feabfdfe38c65b599c4993d227328c231fca

 runc:

  Version:          1.1.8

  GitCommit:        v1.1.8-0-g82f18fe

 docker-init:

  Version:          0.19.0

  GitCommit:        de40ad0

cheeren@cheeren-virtual-machine:~$ 


成功了!

2023年8月9日 星期三

有什麼Linux工具,可以產生隨機複雜的密碼?

 Windows上,從網路上可以找到免費工具來產生複雜的密碼(雖然來源可疑)。而在Linux上呢,有三種Open Source的Linux工具可以用來生成隨機且複雜的密碼,分別是pwgen、apg和openssl:

pwgen

pwgen:是一種用於生成隨機密碼的工具,可以生成包含字母、數字和符號的密碼。您可以使用以下命令安裝:

以下是Ubuntu的安裝方法:

sudo apt-get install pwgen

以下是Rocky Linux 9.2的安裝方法 (本文中,所有在Rocky Linux上的安裝方法均適用於CentOS 7/8以及RHEL):

sudo yum install epel-release -y

sudo yum install pwgen perl-Digest-SHA -y

 

然後,您可以使用以下命令生成一組包含 16 個字符的隨機密碼:

pwgen 16 1

pwgen 16 1

pwgen的缺點在於只會出現大小寫字母和數字,不會有特殊符號。其實,這樣對大部份應用上來說已經是相當足夠了;尤其部份網路銀行或部份購物網站,密碼無法使用特殊符號,這時候完全適合使用;然而,對於一般在目前黑客到處橫行的網路環境下使用來說,的確比較容易被有心人暴力破解。

 

apg

apg:另一種用於生成隨機密碼的工具,可以生成包含字母、數字和符號的密碼。您可以使用以下命令安裝:

以下是Ubuntu上的安裝方式法:

sudo apt-get install apg

以下是Rocky Linux 9.2上的安裝方法:

sudo yum install apg -y

然後,您可以使用以下命令生成一組包含 16 個字符的隨機密碼:

apg -a 1 -n 1 -m 16 -x 16 -M SNCL

用apg產生一組16個字符的密碼

apg本來就是為了自動生成複雜密碼用的。上述指令的參數在此說明一下:-M可以指定產生的是什麼符號,大寫是必須有,小寫則只是可能會有。然後S代表特殊符號,N代表數字,C代表大寫,L代表小寫。-m代表最少幾個字母。-x代表最多幾個字母。-n出現幾組。-a使用的演算法。

Ubuntu版本的apg如果你什麼參數都不下,預設的輸出是六組長度不一的密碼,而且在密碼後方還註明記憶的方式:

Ubuntu上apg的預設輸出







是不是超強大的?

apg是這三者當中可以產生最混亂隨機字串的一種工具,功能最強安裝又簡單,是三種方式中我最推薦使用的。但是它的缺點是參數多,光是要記就很頭痛。然而Ubuntu版本的又更強大。建議用在需要產生複雜密碼的場合。

 

openssl

openssl:一種用於加密和解密資料的工具,也可以用於生成隨機密碼。您可以使用以下兩道命令中的任一種來生成一組包含 16 個字符的隨機密碼,上面那道指令可以產生含有特殊符號的;下列那道指令卻只會生成數字和a到f的小寫文字(其實就是16位元數字):

openssl rand -base64 16 | cut -c1-16

openssl rand -hex 16 | cut -c1-16

OpenSSL產生的祕碼




openssl在大部份的Linux/BSD都有,大概應該預設安裝就在系統中,可以說唾手可得。但是BASE64編碼方式有其限制,也就是說,可能不夠隨機,較易被破解。尤其上述的第二種產生出來的密碼,極度不安全,所以非常不建議使用。

要使用openssl產生的密碼的場合,應該是在你沒有安裝軟體的權限,又緊急需要產生密碼的情況下吧。

來個結語吧。

目前大家在用的Windows,無論是Windows 10還是Windows 11,都已經可以啟動WSL(Windows Subsystem for Linux,適用於Linux的Windows子系統)。所以,你可以從Microsoft Store上安裝Linux,比如我就裝了Ubuntu 22.04 LTS。當你如果像我一樣安裝了Linux,那麼你就可以裝上一些Linux的Open Source應用來使用,不必再被Windows的圖形界面給捆綁。像本文介紹的三種產生密碼的工具,就變成你一定會有的好工具,何不樂哉?


值得一看有關 AI 的文章

 原文: Vibe Coding Is Over. What Comes Next Is Much Harder.   以下是 Gemini 對這篇文章的分析和總結: 這篇文章探討了「氛圍編碼」(Vibe Coding)熱潮後的現狀與未來挑戰。所謂 Vibe Coding 是由 ...