如何在Raspberry Pi上設置兩因素身份驗證

A Raspberry Pi sitting on a laptop keyboard.
Kiklas/ShutterstockKiklas /快門

The Raspberry Pi is everywhere now, which is why it’s caught the eye of threat actors and cybercriminals. We’ll show you how to secure your Pi with two-factor authentication.

Raspberry Pi現在無處不在,這就是為什么它引起了威脅參與者和網絡犯罪分子的關注。 我們將向您展示如何通過兩步驗證來保護您的Pi。

驚人的樹莓派 (The Amazing Raspberry Pi)

The Raspberry Pi?is a single-board computer. It launched in the U.K. in 2012 with the intent of getting children to tinker with, create, and learn code. The original form factor was a credit-card-sized board, powered by a phone charger.

Raspberry Pi是單板計算機。 它于2012年在英國推出,旨在讓孩子們修補,創建和學習代碼。 最初的尺寸是信用卡大小的板,由電話充電器供電。

It provides HDMI output, USB ports, network connectivity, and runs Linux. Later additions to the line included even smaller versions designed to be incorporated in products or run as headless systems. Prices range from $5 for the minimalist Pi Zero, to $75 for the Pi 4 B/8 GB.

它提供HDMI輸出,USB端口,網絡連接并運行Linux。 該產品線后來的增加包括甚至更小版本的產品,這些產品設計用于產品或作為無頭系統運行。 價格從極簡的Pi Zero的5美元到Pi 4 B / 8 GB的75美元不等。

Its success has been incredible; over 30 million of these tiny computers have sold worldwide. Hobbyists have done amazing and inspiring things with them, including floating one to the edge of space?and back on a balloon.

它的成功令人難以置信。 這些微型計算機在全球已售出超過3000萬臺。 業余愛好者已經與他們一起完成了令人驚奇和啟發性的事情,包括將一個漂浮在太空邊緣然后放回氣球上。

Alas, once a computing platform becomes sufficiently widespread it inevitably attracts the attention of cybercriminals. It’s dreadful to think of how many Pi’s are using the default user account and password. If your Pi is public-facing and accessible from the internet by Secure Shell (SSH), it must be secure.

las,一旦計算平臺變得足夠普及,它不可避免地會引起網絡犯罪分子的關注。 考慮到有多少Pi正在使用默認用戶帳戶和密碼,這真是令人恐懼。 如果您的Pi是面向公眾的,并且可以通過Secure Shell (SSH)從Internet訪問,則它必須是安全的。

Even if you don’t have any valuable data or software on your Pi, you need to protect it because your Pi isn’t the actual target—it’s just a way to get into your network. Once a threat actor has a foothold in a network, he’ll pivot to the other devices in which he’s actually interested.

即使您的Pi上沒有任何有價值的數據或軟件,您也需要對其進行保護,因為您的Pi并不是真正的目標-這只是進入網絡的一種方式。 一旦威脅參與者在網絡中立足,他將轉向他真正感興趣的其他設備。

兩要素認證 (Two-Factor Authentication)

Authentication—or gaining access to a system—requires one or more factors. Factors are categorized as the following:

身份驗證(或獲得對系統的訪問權限)需要一個或多個因素。 因素分為以下幾種:

  • Something you know:?Such as a password or -phrase.

    您知道的一些信息:例如密碼或短語。

  • Something you have:?Like a cell phone, physical token, or dongle.

    您擁有的東西:例如手機,物理令牌或加密狗。

  • Something you are:?A biometric reading, like a fingerprint or retinal scan.

    您是:生物識別讀數,例如指紋或視網膜掃描。

Multifactor authentication (MFA) requires a password, and one or more items from the other categories.?For our example, we’re going to use a password and cell phone. The cell phone will run a Google authenticator app, and the Pi will run a Google authentication module.

多因素身份驗證(MFA)要求輸入密碼以及其他類別中的一項或多項。 對于我們的示例,我們將使用密碼和手機。 手機將運行Google身份驗證器應用程序,Pi將運行Google身份驗證模塊。

A cell phone app is linked to your Pi by scanning a QR code. This passes some seed information to your cell phone from the Pi, ensuring their number-generation algorithms produce the same codes simultaneously.? The codes are referred to as?time-based, one-time passwords (TOTP).

手機應用通過掃描QR碼鏈接到您的Pi。 這會將一些種子信息從Pi傳遞到您的手機,以確保其數字生成算法同時生成相同的代碼。 這些代碼稱為基于時間的一次性密碼(TOTP)。

When it receives a connection request, your Pi generates a code. You use the authenticator app on your phone to see the current code, and then your Pi will ask you for your password and authentication code. Both your password and the TOTP must be correct before you’re allowed to connect.

當它收到連接請求時,您的Pi會生成一個代碼。 您使用手機上的身份驗證器應用程序查看當前代碼,然后您的Pi會要求您提供密碼和驗證碼。 允許您連接之前,您的密碼和TOTP都必須正確。

配置Pi (Configuring the Pi)

If you usually SSH onto your Pi, it’s likely it’s a headless system, so we’ll configure it over an SSH connection.

如果您通常將SSH連接到Pi,則可能是無頭系統,因此我們將通過SSH連接對其進行配置。

It’s safest to make two SSH connections: one to do the configuring and testing, and another to act as a safety net. This way, if you lock yourself out of your Pi, you’ll still have the second active SSH connection active. Changing SSH settings won’t affect an in-progress connection, so you can use the second one to reverse any changes and remedy the situation.

建立兩個SSH連接是最安全的:一個進行配置和測試,另一個充當安全網。 這樣,如果您將自己鎖定在Pi之外,您仍將保持第二個活動的SSH連接活動。 更改SSH設置不會影響正在進行的連接,因此您可以使用第二個SSH撤消任何更改并糾正這種情況。

If the worst happens and you’re completely locked out via SSH, you’ll still be able to connect your Pi to a monitor, keyboard, and mouse, and then log in to a regular session. That is, you can still sign in, as long as your Pi can drive a monitor. If it can’t, however, you really need to keep the safety net SSH connection open until you’ve verified that two-factor authentication is working.

如果最壞的情況發生了,并且您已完全通過SSH鎖定,您仍然可以將Pi連接到顯示器,鍵盤和鼠標,然后登錄到常規會話。 也就是說,只要您的Pi可以驅動顯示器,您仍然可以登錄。 但是,如果不能,那么您真的需要保持安全網SSH連接的打開狀態,直到您確認兩因素身份驗證有效。

The ultimate sanction, of course, is to reflash the operating system onto the Pi’s micro SD card, but let’s try to avoid that.

當然,最終的制裁是將操作系統重新刷新到Pi的micro SD卡上,但是讓我們嘗試避免這種情況。

First, we need to make our two connections to the Pi. Both commands take the following form:

首先,我們需要與樹莓派建立兩個連接。 這兩個命令都采用以下形式:

ssh pi@watchdog.local
ssh pi@watchdog.local in a terminal window.

The name of this Pi is “watchdog,” but you’ll type the name yours instead. If you’ve changed the default username, use that, too; ours is “pi.”

該Pi的名稱是“看門狗”,但是您將鍵入您的名字。 如果您更改了默認用戶名,也請使用該用戶名。 我們的是“ pi”。

Remember, for safety, type this command twice in different terminal windows so you have two connections to your Pi. Then, minimize one of them, so it’s out of the way and won’t be closed accidentally.

請記住,為安全起見,請在不同的終端窗口中鍵入此命令兩次,以使您與Pi有兩個連接。 然后,最小化其中之一,以免干擾,不會意外關閉。

After you connect, you’ll see the greeting message. The prompt will show the username (in this case, “pi”), and the name of the Pi (in this case, “watchdog”).

連接后,您將看到問候消息。 提示符將顯示用戶名(在本例中為“ pi”)和Pi的名稱(在本例中為“看門狗”)。

An SSH connection to a Raspberry Pi in a terminal window.

You need to edit the “sshd_config” file. We’ll do so in the nano text editor:

您需要編輯“ sshd_config”文件。 我們將在nano文本編輯器中執行此操作:

sudo nano /etc/ssh/sshd_config
sudo nano /etc/ssh/sshd_config in a terminal window.

Scroll through the file until you see the following line:

滾動瀏覽文件,直到看到以下行:

ChallengeResponseAuthentication no

Replace the “no” with “yes.”

將“否”替換為“是”。

sshd_config file opened in the nano editorwith the ChallengeResponseAuthentication line highlighted, in a terminal window.

Press Ctrl+O to save your changes in nano, and then press Ctrl+X to close the file. Use the following command to restart the SSH daemon:

按Ctrl + O將更改保存在nano中,然后按Ctrl + X關閉文件。 使用以下命令重新啟動SSH守護程序:

sudo systemctl restart ssh
sudo systemctl restart ssh in a terminal window.

You need to install the Google authenticator, which is a Pluggable Authentication Module (PAM) library. The application (SSH) will call the Linux PAM interface, and the interface finds the appropriate PAM module to service the type of authentication being requested.

您需要安裝Google身份驗證器,它是一個可插入身份驗證模塊(PAM)庫。 應用程序(SSH)將調用Linux PAM接口,并且該接口找到適當的PAM模塊以服務于請求的身份驗證類型。

Type the following:

輸入以下內容:

sudo apt-get install libpam-google-authenticator
sudo apt-get install libpam-google-authenticator in a terminal window.

安裝應用 (Installing the App)

The Google Authenticator app is available for iPhone?and?Android, so just install the appropriate version for your cell phone. You can also use Authy and other apps that support this type of authentication code.

Google Authenticator應用適用于iPhone和Android ,因此只需為您的手機安裝適當的版本即可。 您還可以使用Authy和其他支持此類身份驗證代碼的應用。

Google Authenticator App icon on an Android cell phone.

配置兩因素身份驗證 (Configuring Two-Factor Authentication)

In the account you’ll be using when you connect to the Pi via SSH, run the following command (do not include the?sudo?prefix):

在通過SSH連接到Pi時要使用的帳戶中,運行以下命令(不包括sudo前綴):

google-authenticator

You’ll be asked if you want the authentication tokens to be time-based; press Y, and then hit Enter.

系統將詢問您是否希望身份驗證令牌基于時間; 按Y,然后按Enter。

A Quick Response (QR) code is generated, but it’s scrambled because it’s wider than the 80-column terminal window. Drag the window wider to see the code.

生成了快速響應(QR)代碼,但由于它比80列的終端窗口寬,因此已被加擾。 將窗口更寬地拖動以查看代碼。

You’ll also see some security codes beneath the QR code. These are written to a file called “.google_authenticator,” but you might want to make a copy of them now. If you ever lose the ability to obtain a TOTP (if you lose your cell phone, for example), you can use these codes to authenticate.

您還將在QR碼下方看到一些安全碼。 它們被寫入名為“ .google_authenticator”的文件中,但是您現在可能想要復制它們。 如果您失去了獲得TOTP的能力(例如,如果您丟失了手機),則可以使用這些代碼進行身份驗證。

You must answer four questions, the first of which is:

您必須回答四個問題,第一個是:

Do you want me to update your "/home/pi/.google_authenticator" file? (y/n)

Press Y, and then hit Enter.

按Y,然后按Enter。

Do you want me to update your "/home/pi/.google_authenticator" file? (y/n) in a terminal window.

The next question asks whether you want to prevent multiple uses of the same code within a 30-second window.

下一個問題詢問您是否要防止在30秒的窗口內多次使用同一代碼。

Press Y, and then hit Enter.

按Y,然后按Enter。

Do you want to disallow multiple uses of the same authentication token? (y/n) in a terminal window.

The third question asks whether you want to widen the window of acceptance for the TOTP tokens.

第三個問題詢問您是否要擴大TOTP令牌的接受范圍。

Press N in answer to this, and then press Enter.

在回答中按N,然后按Enter。

Do you want to do so? (y/n) in a terminal window.

The last question is: “Do you want to enable rate-limiting?”

最后一個問題是:“您要啟用速率限制嗎?”

Type Y, and then hit Enter.

鍵入Y,然后按Enter。

Do you want to enable rate-limiting? (y/n) in a terminal window.

You’re returned to the command prompt. If necessary, drag the terminal window wider and/or scroll up in the terminal window so you can see the entire QR code.

您將返回到命令提示符。 如有必要,將終端窗口更寬地拖動和/或在終端窗口中向上滾動,以查看整個QR碼。

On your cell phone open the authenticator app, and then press the plus sign (+) at the bottom-right of the screen. Select “Scan a QR Code,” and then scan the QR code in the terminal window.

在您的手機上,打開身份驗證器應用程序,然后按屏幕右下角的加號(+)。 選擇“掃描QR碼”,然后在終端窗口中掃描QR碼。

A new entry will appear in the authenticator app named after the hostname of the Pi, and a six-digit TOTP code will be listed beneath it. It’s displayed as two groups of three digits to make reading it easier, but you must type it as one, six-digit number.

一個新條目將出現在身份驗證器應用程序中,該應用程序以Pi的主機名命名,并在其下方列出一個六位數的TOTP代碼。 它被顯示為兩組,每組三個數字,以便于閱讀,但是您必須將其鍵入一個六位數的數字。

An animated circle beside the code indicates how much longer the code will be valid: a full circle means 30 seconds, a half-circle means 15 seconds, and so on.

代碼旁邊的動畫圓圈表示該代碼有效的時間:一個完整??的圓圈表示30秒,一個半圓圈表示15秒,依此類推。

鏈接在一起 (Linking It All Together)

We’ve got one more file to edit. We have to tell SSH which PAM authentication module to use:

我們還有一個文件要編輯。 我們必須告訴SSH使用哪個PAM身份驗證模塊:

sudo nano /etc/pam.d/sshd
sudo nano /etc/pam.d/sshd in a terminal window.

Type the following lines near the top of the file:

在文件頂部附近鍵入以下幾行:

#2FA
auth required pam_google_authenticator.so
auth required pam_google_authenticator.so added to the sshd file in an editor, in a terminal window.

You can also choose when you want to be asked for the TOTP:

您還可以選擇何時要求輸入TOTP:

  • After you’ve entered your password: Type the previous lines below “@include common-auth,” as shown in the image above.

    輸入密碼后:如上圖所示,在“ @include common-auth”下面輸入前幾行。

  • Before you’re asked for your password: Type the previous lines?above “@include common-auth.”

    在要求您輸入密碼之前:在“ @include common-auth”上方輸入前幾行。

Note the underscores (_) used in “pam_google_authenticator.so,” rather than the hyphens (-) we used earlier with the apt-get command to install the module.

請注意“ pam_google_authenticator.so”中使用的下劃線(_),而不是我們之前使用apt-get命令安裝模塊時使用的連字符(-)。

Press Ctrl+O to write the changes to the file, and then press Ctrl+X to close the editor. We need to restart SSH one final time, and then we’re done:

按Ctrl + O將更改寫入文件,然后按Ctrl + X關閉編輯器。 我們需要在最后一次重新啟動SSH,然后完成:

sudo systemctl restart ssh
sudo systemctl restart ssh in a terminal window.

Close this SSH connection, but leave the other safety net SSH connection running until we’ve verified this next step.

關閉此SSH連接,但使其他安全網SSH連接保持運行狀態,直到我們驗證了此下一步。

Make sure the authenticator app is open and ready on your cell phone, and then open a new SSH connection to the Pi:

確保身份驗證器應用已打開并在手機上準備就緒,然后打開與Pi的新SSH連接:

ssh pi@watchdog.local
ssh pi@watchdog.local in a terminal window.

You should be asked for your password, and then for the code. Type the code from your cell phone without any spaces between the numbers.?Like your password, it’s not echoed on the screen.

應該要求您輸入密碼,然后輸入代碼。 鍵入手機中的密碼,數字之間不要有空格。 就像您的密碼一樣,它不會在屏幕上回顯。

If everything goes according to plan, you should be allowed to connect to the Pi; if not, use your safety net SSH connection to review the previous steps.

如果一切都按計劃進行,則應允許您連接到Pi。 如果不是,請使用您的安全網SSH連接查看前面的步驟。

比抱歉更好安全 (Better Safer Than Sorry)

Did you notice the “r” in “safer” above?

您是否注意到上面“更安全”中的“ r”?

Indeed, you’re now safer than you were previously when connecting to a Raspberry Pi, but nothing is ever 100 percent safe. There are ways to circumvent two-factor authentication. These rely on social engineering, man-in-the-middle?and man-at-the-endpoint attacks, SIM swapping, and other advanced techniques that, obviously, we’re not going to describe here.

確實,與連接Raspberry Pi的連接相比,您現在比以前更安全,但是沒有100%安全。 有一些方法可以規避兩因素身份驗證。 這些依賴于社會工程,中間人攻擊和端點人攻擊, SIM卡交換以及其他高級技術,顯然,我們將不在這里描述。

So, why bother with all this if it’s not perfect? Well, for the same reason you lock your front door when you leave, even though there are people who can pick locks—most can’t.

那么,如果這還不夠完美,為什么還要煩惱呢? 好吧,出于同樣的原因,即使有人可以選鎖,但離開時還是要鎖上前門,而大多數人卻不能。

翻譯自: https://www.howtogeek.com/676077/how-to-set-up-two-factor-authentication-on-a-raspberry-pi/

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/278254.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/278254.shtml
英文地址,請注明出處:http://en.pswp.cn/news/278254.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Laravel Passport里的授權類型介紹

本文來自pilishen.com----原文鏈接; 歡迎來和pilishen一起學習php&Laravel;學習群:109256050OAuth2是一個安全框架,控制著程序受保護部分的準入,主要是控制不同的客戶端如何來調取API,保證它們在請求相應資源的時候…

vue 開發環境搭建

1.創建vue項目 1.node js 生成項目,編譯項目 2.hbuilder 開發環境 1.下載安裝node js http://nodejs.cn/download/ 確認是否安裝成功 如果安裝不了 代碼錯誤2503 解決方法: 管理員命令運行cmd; cd\ cd C:\Users\Administrator\Desktop msiexec/package n…

iphone視圖放大_如何將iPhone用作放大鏡

iphone視圖放大It’s a common problem: Some things are just too hard to see. Usually, they’re too far away, too dark, or too small. With a feature called Magnifier, your iPhone can function as a magnifying glass and sight aid. Here’s how to use it. 這是一…

chmod權限

本文引用:https://www.cnblogs.com/zhangym/p/5826200.html linux數字權限解釋 644 第一位代表文件所有者的權限,第二位代表同組用戶的權限,第三位代表其他用戶的權限. 讀取權限等于4,用r表示;寫入權限2,用w表示;執行權限1,用x表示. 通過4、2、1組合,得到以下幾種權…

輸出最大值MXNet實現

網絡結構,輸入為2個數,先經過10個節點的全連接層,再經過10個節點的ReLu,再經過10個節點的全連接層,再經過1個節點的全連接層,最后輸出。 #-*-coding:utf-8-*- import logging import math import random im…

discord linux_如何在Discord中應用文本格式

discord linuxDiscord allows for text-and audio-based chatting between gamers and other like-minded individuals. If you want to make a bigger impact on Discord, you can use formatting to jazz up your text-based messages. Here’s how. Discord允許游戲玩家和其…

一張圖看懂阿里云網絡產品[十二]云企業網

2019獨角獸企業重金招聘Python工程師標準>>> 摘要: 阿里云致力于為用戶提供優質、高效、穩定的網絡傳輸環境,云企業網(Cloud Enterprise Network)將提供一種能夠快速構建混合云和分布式業務系統的全球網絡,…

# 2019-2020.3 《java程序設計》第一周學習總結

2019-2020-3 《Java 程序設計》第一周學習總結 在本周的學習中,學習到了好多也收獲了好多,從最基礎的安裝虛擬機開始,根據老師的博客中的教程一步一步的進行,在這過程中也遇到了好多問題,因為是初步接觸Linux系統&…

聊聊Java反射

反射是Java最重要的特性。通過Java反射可以在運行時知道一個類的所有成員和方法,知道一個對象的類類型、成員和方法的所有信息,進而調用對象的方法或生成對象的代理或包裝類。Java是面向對象語言,除了靜態變量或原始數據類型外都是完全面向對…

01. 把存儲過程結果集SELECT INTO到臨時表

原文:01. 把存儲過程結果集SELECT INTO到臨時表在開發過程中,很多時候要把結果集存放到臨時表中,常用的方法有兩種。 一. SELECT INTO 1. 使用select into會自動生成臨時表,不需要事先創建 select * into #temp from sysobjects select * fro…

day5學python 基礎+裝飾器內容

基礎裝飾器內容 遞歸特性# 1.必須有一個明確的結束條件# 2.每次進入更深一層遞歸時,問題規模相比上次遞歸應有所減少# 3.遞歸效率不高 def run(n):print(n)if int(n/2)>0:return run(n / 2)print("-->",n) run(10) 局部變量與全局變量知識 1.全局變…

如何在Windows 10上跳過回收站以刪除文件

Windows 10 normally sends files you delete to the Recycle Bin. They’ll be kept until you empty it—or, in some cases, until Windows 10 automatically empties your Recycle Bin. Here’s how to skip the Recycle Bin and delete files immediately. Windows 10通常…

OSChina 周日亂彈 —— 我叫張一條

2019獨角獸企業重金招聘Python工程師標準>>> Osc亂彈歌單(2018)請戳(這里) 【今日歌曲】 萊布妮子 :分享Lube的單曲《Skoro dembel》 《Skoro dembel》- Lube 手機黨少年們想聽歌,請使勁兒戳&am…

面向對象初識

一. 面向對象初識 1.1 回顧面向過程編程vs函數式編程 # 面向過程編程 測量對象的元素個個數。 s1 fjdsklafsjda count 0 for i in s1:count 1l1 [1,2,3,4] count 0 for i in l1:count 1 面向過程編程def func(s):count 0for i in s:count 1return count …

iOS逆向:在任意app上開啟malloc stack追蹤內存來源

lldb有一個內存調試工具malloc stack,開啟以后就可以查看某個內存地址的malloc和free記錄,追蹤對象是在哪里創建的。 這個工具可以打印出對象創建的堆棧,而在逆向時,也經常需要追蹤某些方法的調用棧,如果可以隨時打印出…

【CH4302】Interval GCD

思路:線段樹維護a的差分數組的gcd, 因為$gcd(a_1,a_2,a_3,...,a_n)gcd(a_1,a_2-a_1,a_3-a_2,...,a_n-a_{n-1})$。 原區間修改可以轉化為差分數組上的兩次單點修改。 因為實際計算時還需要原數,所以用樹狀數組維護b的增減量。 詢問時&#xff…

Vue 的路由實現 Hash模式 和 History模式

Hash 模式: Hash 模式的工作原理是onhashchange事件,Window對象可以監聽這個事件... 可以通過改變路徑的哈希值,來實現歷史記錄的保存,發生變化的hash 都會被瀏覽器給保存下來,所以下次盡管瀏覽器沒有請求服務器,但是還…

我的第一次——網站備案

暫無內容 轉載于:https://my.oschina.net/vright/blog/1784979

使用LiveClick升級您的實時書簽

If you like to subscribe to feeds using Firefox’s Live Bookmarks feature, the LiveClick extension gives you so many upgrades that I can only cover the highlights of how great it is. 如果您想使用Firefox的“實時書簽”功能訂閱供稿,則LiveClick擴展程…

操作系統的概論梳理

轉載于:https://www.cnblogs.com/hclhechunlu/p/10477470.html