客製化sshd的ciphers (RHEL8)

很多 Linux 系統參數檢核表都有一個項目,就是在 /etc/ssh/sshd_config 裡加入下面這兩行,以禁用 sshd 不安全的 cipher。

Ciphers aes128-ctr,aes192-ctr,aes256-ctr
MACs hmac-sha1,hmac-ripemd160,hmac-sha2-256,hmac-sha2-512

但很有趣的是,RHEL8 sshd_config 裡的 comment 是這樣寫的

# This system is following system-wide crypto policy. The changes to
# crypto properties (Ciphers, MACs, ...) will not have any effect here.
# They will be overridden by command-line options passed to the server
# on command line.
# Please, check manual pages for update-crypto-policies(8) and sshd_config(5).

他說,這系統是依照系統的 crypto 原則,所以在這個設定檔裡加 Ciphers, MACs 是沒有效果的,會被傳遞給 sshd 的 command-line 選項給覆蓋掉。

來看看 sshd.service 的內容

# ...省略...
[Service]
Type=notify
EnvironmentFile=-/etc/crypto-policies/back-ends/opensshserver.config
EnvironmentFile=-/etc/sysconfig/sshd
ExecStart=/usr/sbin/sshd -D $OPTIONS $CRYPTO_POLICY
# ...省略...

首先載入 /etc/crypto-policies/back-ends/opensshserver.config 裡的環境變數,然後再載入 /etc/sysconfig/sshd 裡的環境變數,所以後者蓋掉前者。

那修改方法就很清楚了,就是修改 /etc/sysconfig/sshd 這個檔案就可以,把裏面 CRYPTO_POLICY= 前面的 # 拿掉,加入參數:

CRYPTO_POLICY="-oCiphers=aes128-ctr,aes192-ctr,aes256-ctr -oMACs=hmac-sha1,hmac-sha2-256,hmac-sha2-512"

然後重新啟動 sshd 就可以。

附帶一提,OpenShift CoreOS 也是用類似的方式修改,只是需要透過 MachineConfig。

參考資料:

RHEL8強制解除註冊

前兩天遇到的狀況是這樣,公司裡的 RHEL8 主機是註冊到 Satellite 上,但 Satellite 主機因為機房設備升級,開不了機,可是這台 RHEL8 主機又急著要安裝套件,那就得先解除註冊。

第一步,是先處理 /etc/rhsm/rhsm.conf ,註冊到 Satellite 時,rhsm.conf 裡的設定會被修改,表明註冊到 Satellite。在這裡可以找到備份的 rhsm.conf ,把這檔案復原回去。

第二步,是移除套件,在註冊到 Satellite 時,會安裝一個套件,這個套件包含了註冊到 Satellite 的資訊以及憑證。套件的名稱裡有 katello-ca ,找到之後,用 rpm -e 或 yum remove 移除。

第三步,是移除 /etc/pki/consumer 跟 /etc/pki/entitlement ,這裡有 subscription-manager 註冊後取得的資訊。

rm -rf /etc/pki/consumer
rm -rf /etc/pki/entitlement
subscription-manager clean

處理完之後,就可以用 subscription-manager register 來註冊到 Red Hat 了。

參考資料