中文字幕 另类精品,亚洲欧美一区二区蜜桃,日本在线精品视频免费,孩交精品乱子片免费

<sup id="3hn2b"></sup>

    1. <sub id="3hn2b"><ol id="3hn2b"></ol></sub><legend id="3hn2b"></legend>

      1. <xmp id="3hn2b"></xmp>

      2. "); //-->

        博客專欄

        EEPW首頁 > 博客 > 嵌入式Linux下Dropbear SSH配置優(yōu)化

        嵌入式Linux下Dropbear SSH配置優(yōu)化

        發(fā)布人:toradex 時(shí)間:2023-05-31 來源:工程師 發(fā)布文章

        By Toradex秦海

        1). 簡介

        嵌入式 Linux  由于運(yùn)行平臺(tái)通常資源受限同時(shí)對穩(wěn)定性要求高,因此需要比較精簡,那么針對 SSH 服務(wù)器/客戶端應(yīng)用,通常也不使用龐大的 OpenSSH,而是采用十分精簡的 Dropbear SSH工具。Dropbear 是一個(gè)基于 MIT License 的開源軟件,其一些基本信息可以參考如下軟件發(fā)布頁面:

        https://matt.ucc.asn.au/dropbear/dropbear.html

         

        本文所演示的平臺(tái)來自于Toradex Apalis iMX8 嵌入式平臺(tái),基于 NXP iMX8 系列 ARM 處理器,核心為 Cortex-A52/A53 

         

         

        2). 硬件準(zhǔn)備

        a).  Apalis iMX8 ARM 核心版配合 Apalis Eva Board 載板,并連接調(diào)試串口和網(wǎng)口以便測試。

         

         

        3). 具體配置說明

        a). Apalis iMX8 模塊標(biāo)準(zhǔn) Ycoto Linux BSP 中已經(jīng)包含 Dropbear 相關(guān)軟件,不過由于默認(rèn)配置為了開發(fā)測試方便,默認(rèn)使能了 debug-tweaks 功能(比如這樣可以允許 root 賬戶無密碼登錄),這樣如下面 Ycoto Project/Openembedded 相關(guān)文件說明也就同時(shí)也使能了 weak ciphers

         

        ./ layers/meta-toradex-demos/recipes-core/dropbear/dropbear_%.bbappend

        ---------------------------------------

        # THE Eclipse RSE system explorer uses a ssh client which cannot cope with the

        # dropbear ssh server if weak ciphers are disabled.

        # If debug-tweaks is set in IMAGE_FEATURES then enable also weak ciphers.

        # With debug-tweaks we allow password less root access, enforcing strong

        # ciphers is pointless anyway.

        PACKAGECONFIG = "${@bb.utils.contains("IMAGE_FEATURES", "debug-tweaks", "", "disable-weak-ciphers",d)}"

        ---------------------------------------

         

        b). 為了使 Dropbear SSH安全性更高,可以在 Ycoto 編譯環(huán)境下參考如下 patch 文件修改關(guān)閉 debug-tweaks weak ciphers。因?yàn)橥瑫r(shí)這樣也關(guān)閉了 root 用戶無密碼登錄,因此也需要給 root 用戶配置默認(rèn)密碼。

        ./ local.conf 文件修改 patch

        ---------------------------------------

        --- a/build/conf/local.conf 2023-05-30 12:16:33.780891419 +0800

        +++ b/build/conf/local.conf 2023-05-31 10:55:36.841801362 +0800

        @@ -277,3 +277,9 @@

         include conf/machine/include/${MACHINE}.inc

         

         # DO NOT SET THE MACHINE AFTER THE ABOVE INCLUDE

        +# accept the Freescale EULA

        +ACCEPT_FSL_EULA = "1"

        +# add root password

        +EXTRA_IMAGE_FEATURES = "allow-root-login package-management"

        +INHERIT += "extrausers"

        +EXTRA_USERS_PARAMS = "usermod -P Abcd1234 root"

        ---------------------------------------

         

        ./ 參考這里的說明將上述修改下重新編譯生成的 Ycoto Linux Image 通過 Toradex Easy Installer 更新到 Apalis iMX8 模塊,此時(shí)測試無論本地串口登錄還是遠(yuǎn)程SSH登錄 root 用戶都需要輸入預(yù)設(shè)的密碼了,增強(qiáng)了安全性。

         

        c). 為了進(jìn)一步提高 SSH 安全性,可以創(chuàng)建普通 user 用戶用于遠(yuǎn)程登錄,而禁止 root 用戶 SSH 遠(yuǎn)程登錄。這樣也可以通過限制 user 用戶的權(quán)限來提高系統(tǒng)安全性。

        ./ 創(chuàng)建新的 user 用戶

        ---------------------------------------

        root@apalis-imx8-07308034:~# useradd testuser

        root@apalis-imx8-07308034:~# passwd testuser

        New password:

        Retype new password:

        passwd: password updated successfully

        ---------------------------------------

         

        ./ 禁止 root 用戶 SSH 登錄,參考如下 patch 修改 /etc/default/dropbear 文件

        ---------------------------------------

        --- a/etc/default/dropbear

        +++ b/etc/default/dropbear

        @@ -1,2 +1,2 @@

         # Disallow root logins by default

        -DROPBEAR_EXTRA_ARGS=""

        +DROPBEAR_EXTRA_ARGS=" -w"

        ---------------------------------------

         

        ./ 測試使用 testuser 用戶遠(yuǎn)程 SSH 登錄成功, root 用戶登錄失效

        ---------------------------------------

        ### root login ###

        $ ssh root@10.20.1.168

        root@10.20.1.168's password:

        Permission denied, please try again.

        ### testuser login ###

        $ ssh testuser@10.20.1.168

        testuser@10.20.1.168's password:

        mkdir: cannot create directory '/run/user/1000': Permission denied

        chmod: cannot access '/run/user/1000': No such file or directory

        apalis-imx8-07308034:~$

        ---------------------------------------

         

        ./ 另外,如果需要本地串口 testuser 或者 root 用戶自動(dòng)登錄,可以參考如下 patch 修改

        ---------------------------------------

        --- a/lib/systemd/system/serial-getty@.service

        +++ b/lib/systemd/system/serial-getty@.service

        @@ -30,7 +30,7 @@

         

         [Service]

         Environment="TERM=xterm"

        -ExecStart=-/sbin/agetty -8 -L %I 115200 $TERM

        +ExecStart=-/sbin/agetty -8 -a testuser -L %I 115200 $TERM

         Type=idle

         Restart=always

         UtmpIdentifier=%I

        ---------------------------------------

         

        d). 遠(yuǎn)程 SSH 除了默認(rèn)的密碼登錄方式外,還可以開啟安全等級(jí)更高的通過 public key 來無密碼登錄

        ./ 在需要遠(yuǎn)程登錄 Apalis iMX8 設(shè)備的 PC 主機(jī)環(huán)境下通過 ssh-keygen 工具生成 SSH private key/public key pair

        ---------------------------------------

        ### generate 4096-bits key pair ###

        $ ssh-keygen -b 4096

        Generating public/private rsa key pair.

        Enter file in which to save the key (/home/simon/.ssh/id_rsa): /home/simon/local/tmp/ssh-test/id_rsa

        Enter passphrase (empty for no passphrase):

        Enter same passphrase again:

        Your identification has been saved in /home/simon/local/tmp/ssh-test/id_rsa.

        Your public key has been saved in /home/simon/local/tmp/ssh-test/id_rsa.pub.

        The key fingerprint is:

        SHA256:Pr5PQjzRuPMVS3Rrkdtq+7pDVOFMGumBLpFGkjGSEs0 simon@simon-Latitude-5300

        The key's randomart image is:

        +---[RSA 4096]----+

        |   .+..++.. o.++.|

        |   . E..o* o +Bo.|

        |    .   + + +.+* |

        |       . + o =o .|

        |        S . o. . |

        |       o + .  +  |

        |        + o  o . |

        |       . +    o  |

        |        oo.   o=.|

        +----[SHA256]-----+

        ---------------------------------------

         

        ./ 通過 SSH 遠(yuǎn)程命令將生成的 public key 寫入到 Apalis iMX8 dropbear authorized_keys 文件

        ---------------------------------------

        ### create ssh folder on apalis iMX8 device ###

        apalis-imx8-07308034:~$ mkdir /home/testuser/.ssh

        ### add public key to apalis iMX8 authorized_keys file from Host PC remotely ###

        $ ssh testuser@10.20.1.168 "tee -a /home/testuser/.ssh/authorized_keys" < /home/simon/local/tmp/ssh-test/id_rsa.pub

        ---------------------------------------

         

        ./ 參考如下 patch 修改 Apalis iMX8 dropbear 啟動(dòng)配置來使 public key 驗(yàn)證生效

        ---------------------------------------

        --- a/lib/systemd/system/dropbear@.service

        +++ b/lib/systemd/system/dropbear@.service

        @@ -4,9 +4,9 @@

         After=syslog.target dropbearkey.service

         

         [Service]

        -Environment="DROPBEAR_RSAKEY_DIR=/etc/dropbear"

        +Environment="DROPBEAR_RSAKEY_DIR=/home/testuser/.ssh/"

         EnvironmentFile=-/etc/default/dropbear

        -ExecStart=-/usr/sbin/dropbear -i -r ${DROPBEAR_RSAKEY_DIR}/dropbear_rsa_host_key $DROPBEAR

        _EXTRA_ARGS

        +ExecStart=-/usr/sbin/dropbear -i $DROPBEAR_EXTRA_ARGS

         ExecReload=/bin/kill -HUP $MAINPID

         StandardInput=socket

         KillMode=process

        ---------------------------------------

         

        ./ 重啟 Apalis iMX8 使配置生效后,再次嘗試遠(yuǎn)程 SSH 登錄,可以實(shí)現(xiàn)無需密碼而是采用 public key 驗(yàn)證登錄

        ---------------------------------------

        $ ssh -i /home/simon/local/tmp/ssh-test/id_rsa testuser@10.20.1.168

        mkdir: cannot create directory '/run/user/1000': Permission denied

        chmod: cannot access '/run/user/1000': No such file or directory

        apalis-imx8-07308034:~$

        ---------------------------------------

         

        e). 更多關(guān)于 dropbear 工具命令參數(shù)說明可以參考如下

        https://manpages.ubuntu.com/manpages/bionic/man8/dropbear.8.html

         

         

        4). 總結(jié)

        本文基于嵌入式 Linux 簡單演示了 輕量化 SSH 工具軟件 Dropbear 的增強(qiáng)安全性配置供參考。


        *博客內(nèi)容為網(wǎng)友個(gè)人發(fā)布,僅代表博主個(gè)人觀點(diǎn),如有侵權(quán)請聯(lián)系工作人員刪除。



        關(guān)鍵詞: ARM Linux SSH Dropbear NXP iMX8 Toradex Apalis

        相關(guān)推薦

        技術(shù)專區(qū)

        關(guān)閉