Xubuntu22.04でVNCサーバーを起動してsshトンネル経由で画面共有する

Xubuntu 22.04 TLS
TigerVNC Server 1.12.0
OpenSSH 8.9

Xubuntuに必要なパッケージをインストールする。

# apt install ssh tigervnc-scraping-server

sshサーバーを有効化して開始する。

# systemctl enable --now ssh

Xubuntuにログインした状態でvncサーバーを起動する。

$ x0tigervncserver -localhost=yes -securitytypes=none

外部から接続するには下記のコマンドをリモート側で実行しsshポートフォワーディングを開始する。
※-Lオプションはリモート側のlocalhost:12345をホスト側のlocalhost:5900に転送するという意味らしい

$ ssh user@hostname.local.example.com -L 12345:localhost:5900

sshを接続したままの状態でvncビューワーでlocalhost:12345に接続する。

$ xtigervncviewer localhost:12345

smbサーバーの共有ディレクトリをwhiptailで選択してgioでマウントする

Linux Mint 20.3 (Una)
whiptail 0.52.21
libglib2.0-bin 2.64.6

スクリプトを作成する。

#!/bin/bash
directories=("共有1" "共有2" "共有3")
radioList=()
listIndex=0
for index in "${!directories[@]}"
do
    radioList[${listIndex}]=$index
    radioList[${listIndex}+1]=${directories[${index}]}
    radioList[${listIndex}+2]=OFF
    listIndex+=3
done
selectedIndex=$(whiptail --title "共有ディレクトリ" --radiolist "アクセスするディレクトリを選択してください。" 20 80 15 "${radioList[@]}" --notags 3>&1 1>&2 2>&3)
if [ ${#selectedIndex} == 0 ]; then
    exit 0
fi
directory=${directories[${selectedIndex}]}
if [ ! -d /run/user/$UID/gvfs/smb-share:server=samba-server,share=$directory/ ]; then
    echo -e "user\nWORKGROUP\nPassword\n" | gio mount smb://samba-server/$directory 1>/dev/null 2>/dev/null
fi
xdg-open smb://samba-server/$directory/

スクリプトを実行可能にする。

$ chmod +x ~/bin/gio-mount.sh

AlmaLinux8のPostfixでEメールをDKIMで送信する

この記事で設定したPostfixを使用する。

AlmaLinux release 8.5 (Arctic Sphynx)
postfix 3.5.8
opendkim 2.11.0

EPELリポジトリを追加する。

# dnf install epel-release

必要なパッケージをインストールする。

# dnf install opendkim
# dnf install opendkim-tools

鍵を格納するディレクトリを作成する。

# cd /etc/opendkim/keys/
# mkdir hirohiro716.com alias.hirohiro716.com
# chmod 750 *

鍵を作成する。–selectorオプションは1つのドメインに複数の鍵を設定する場合を除き指定する必要はない。

# opendkim-genkey -D /etc/opendkim/keys/hirohiro716.com/ -d hirohiro716.com
# opendkim-genkey -D /etc/opendkim/keys/alias.hirohiro716.com/ -d alias.hirohiro716.com
# chown -R opendkim:opendkim /etc/opendkim/keys/

作成されたdefault.txtを参考にDNSレコードを登録しておく。

default._domainkey.hirohiro716.com TXT 0 v=DKIM1; k=rsa; p=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
_adsp._domainkey.hirohiro716.com TXT 0 dkim=unknown
default._domainkey.alias.hirohiro716.com TXT 0 v=DKIM1; k=rsa; p=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
_adsp._domainkey.alias.hirohiro716.com TXT 0 dkim=unknown

opendkimの設定を変更する。
※変更箇所のみ記載

Mode  sv
SoftwareHeader  no
KeyTable  /etc/opendkim/KeyTable
SigningTable  refile:/etc/opendkim/SigningTable

KeyTableを変更して使用する秘密鍵を指定する。

default._domainkey.hirohiro716.com hirohiro716.com:default:/etc/opendkim/keys/hirohiro716.com/default.private
default._domainkey.alias.hirohiro716.com alias.hirohiro716.com:default:/etc/opendkim/keys/alias.hirohiro716.com/default.private

SigningTableを変更して署名するドメインを指定する。

*@hirohiro716.com default._domainkey.hirohiro716.com
*@alias.hirohiro716.com default._domainkey.alias.hirohiro716.com

サービスを有効化して実行する。

# systemctl enable --now opendkim

Postfixの設定ファイルの最下部に下記を追記する。

# DKIM settings.
smtpd_milters = inet:127.0.0.1:8891
non_smtpd_milters = $smtpd_milters
milter_default_action = accept

Postfixの設定を再読み込みする。

# systemctl reload postfix

Apacheが動いているAlmaLinux8でPostfix用のLet’sEncryptの証明書を取得する

AlmaLinux release 8.5 (Arctic Sphynx)
certbot 1.22.0
apache 2.4.37
postfix 3.5.8

Let’sEncryptの証明書を発行するためのcertbotをインストールする。

# dnf install epel-release
# dnf install certbot

ACMEプロトコル用にApacheの設定を行う。

<VirtualHost *:80>
        ServerName test.example.com
        DocumentRoot /var/lib/letsencrypt/
        <Directory /var/lib/letsencrypt/>
            AllowOverride None
            Options IncludesNoExec
            Require method GET
        </Directory>
</VirtualHost>

Apacheの設定を再読み込みする。

# systemctl reload httpd

SSL証明書を発行する。何度も失敗したりしても制限がかかるので、–dry-runオプションを指定してテストする。

# certbot certonly --webroot -w /var/lib/letsencrypt/ -d test.example.com
-------------------------------------------------------------
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): admin@test.example.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: N
Account registered.
Requesting a certificate for test.example.com

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/test.example.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/test.example.com/privkey.pem
This certificate expires on 2022-08-01.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
 * Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
 * Donating to EFF:                    https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

発行が成功すると下記の場所に証明書が作られる。ほかのサーバーに移行する場合は/etc/letsencrypt/ごとコピーすればOKだった。

/etc/letsencrypt/live/test.example.com/cert.pem
/etc/letsencrypt/live/test.example.com/privkey.pem
/etc/letsencrypt/live/test.example.com/chain.pem
/etc/letsencrypt/live/test.example.com/fullchain.pem

cronで毎朝4時にSSL証明書を更新するジョブを追加する。更新されるかは自動で決定され、更新された場合のみ–deploy-hookオプションで指定されたコマンドが実行される。

0 4 * * * certbot renew --deploy-hook "systemctl reload postfix"

Postfixのmain.cfを編集して証明書の設定をする。
※変更箇所のみ記載

# Certificate settings.
smtpd_tls_cert_file = /etc/letsencrypt/live/test.example.com/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/test.example.com/privkey.pem

AlmaLinux8をPostfix+dovecotでE-mailサーバーにする

・ システムアカウントとE-mailアカウントは別にしたい
・ user1@hirohiro716.comのようなアドレスで主に送受信する
・ 別名でuser1@alias.hirohiro716.comでも受信したい
・ メーリングリストも使用したい
・ AlmaLinuxのバージョン: 8.5
・ Postfixのバージョン: 3.5.8
・ Dovecotのバージョン: 2.3.8
・ プロトコル: smtp/smtps/imaps/pop3s

DNSレコード

先にDNSレコードを登録しておく。
mydomain: email.hirohiro716.com
virtual_mailbox_domains: hirohiro716.com
virtual_alias_domains: alias.hirohiro716.com

email.hirohiro716.com A 0 153.126.160.145
hirohiro716.com A 0 153.126.160.145
hirohiro716.com MX 10 hirohiro716.com
hirohiro716.com TXT 0 v=spf1 +mx ~all
alias.hirohiro716.com A 0 153.126.160.145
alias.hirohiro716.com MX 10 alias.hirohiro716.com
alias.hirohiro716.com TXT 0 v=spf1 +mx ~all

SSL証明書

この手順ではZeroSSLで発行した証明書を使用する。ZeroSSLにログインして発行した証明書のzipファイルを解凍する。

# unzip email.hirohiro716.com.zip -d /etc/ssl/email.hirohiro716.com/

解凍されたファイルは「ca_bundle.crt」「certificate.crt」「private.key」で、中間CA証明書がないので作成する。

# cd /etc/ssl/email.hirohiro716.com/
# cat certificate.crt ca_bundle.crt > fullchain.crt

証明書のSELinuxコンテキストのラベル付けを復元する。

# restorecon -RF /etc/ssl/email.hirohiro716.com/

Dovecot

Dovecotをインストールする。

# dnf install dovecot

SSL証明書の設定をする。
※変更箇所のみ記載

ssl_cert = </etc/ssl/email.hirohiro716.com/fullchain.crt
ssl_key = </etc/ssl/email.hirohiro716.com/private.key

使用するプロトコルを設定する。
※変更箇所のみ記載

protocols = imap pop3

認証の際に受け付けるポート、Postfix認証用ソケットファイルの設定をする。ソケットファイルのパーミッションとか所有者とかはコメントを読む限り0666で問題なさそうなのでそのまま。
※変更箇所のみ記載

service imap-login {
  inet_listener imap {
    port = 0
  }
  inet_listener imaps {
    port = 993
    ssl = yes
  }
}
service pop3-login {
  inet_listener pop3 {
    port = 0
  }
  inet_listener pop3s {
    port = 995
    ssl = yes
  }
}
unix_listener /var/spool/postfix/private/auth {
  mode = 0666
}

バーチャルメールボックス用のシステムアカウントとディレクトリを作成する。

# groupadd -g 5000 vmail
# useradd -u 5000 -g vmail -s /sbin/nologin vmail
# mkdir /var/spool/mail/virtual
# chown vmail:vmail /var/spool/mail/virtual
# chmod 770 /var/spool/mail/virtual

Dovecotにバーチャルメールボックスの場所を設定する。
※変更箇所のみ記載

mail_location = maildir:/var/spool/mail/virtual/%d/%n/Maildir

Dovecotの認証方法に関する設定を変更する。システムアカウントで認証はしない。
※変更箇所のみ記載

#!include auth-system.conf.ext
!include auth-passwdfile.conf.ext
!include auth-static.conf.ext

auth-passwdfile.conf.extはデフォルトのまま使用する。

passdb {
  driver = passwd-file
  args = scheme=CRYPT username_format=%u /etc/dovecot/users
}
userdb {
  driver = passwd-file
  args = username_format=%u /etc/dovecot/users
}

auth-passwdfile.conf.extで指定されているusersファイルを作成する。

user1@hirohiro716.com:{PLAIN}password-1234
user2@hirohiro716.com:{PLAIN}password-5678

auth-static.conf.extを編集して作成したアカウント「vmail」を指定する。homeの指定はしなくても大丈夫だと思われる。
※変更箇所のみ記載

userdb {
  driver = static
  args = uid=vmail gid=vmail
}

Postfix

基本的な設定

Postfixをインストールする。

# dnf install postfix

main.cfを編集して基本的な設定をする。
※変更箇所のみ記載

# Not matching the actual hostname.
myhostname = email.hirohiro716.com
mydomain = $myhostname
myorigin = $mydomain

# Receive mail on all network interfaces.
inet_interfaces = all

# Disable IPv6.
inet_protocols = ipv4

# Specifies the domain that this machine delivers locally.
mydestination = $myhostname, localhost.$mydomain, localhost

# Not publish.
smtpd_banner = $myhostname ESMTP unknown

# Certificate settings.
smtpd_tls_cert_file = /etc/ssl/email.hirohiro716.com/fullchain.crt
smtpd_tls_key_file = /etc/ssl/email.hirohiro716.com/private.key

# Disable user search.
disable_vrfy_command = yes

# SASL settings.
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, defer_unauth_destination

# Client restriction settings.
smtpd_client_restrictions = permit_mynetworks, reject_unknown_client, permit

# HELO restriction settings.
smtpd_helo_required = yes
smtpd_helo_restrictions = permit_mynetworks, reject_unknown_hostname, reject_non_fqdn_hostname, reject_invalid_hostname, permit

# Sender restriction settings.
smtpd_sender_restrictions = permit_mynetworks, reject_unknown_sender_domain, reject_non_fqdn_sender

master.cfを編集して利用するプロトコルの種類を設定する。smtpsのsmtpd_tls_wrappermodeを有効にしないとtcp/465でもSTARTTLSが試行される。
※変更箇所のみ記載

smtp      inet  n       -       n       -       -       smtpd
submission inet n       -       n       -       -       smtpd
smtps     inet  n       -       n       -       -       smtpd
  -o smtpd_tls_wrappermode=yes
メールの容量に関する設定

現在のサイズに関する設定値を確認する。

berkeley_db_create_buffer_size = 16777216
berkeley_db_read_buffer_size = 131072
body_checks_size_limit = 51200
bounce_size_limit = 50000
header_size_limit = 102400
lmdb_map_size = 16777216
mailbox_size_limit = 51200000
message_size_limit = 10240000
tcp_windowsize = 0

メールボックスが50MB、メッセージが10MBに制限されている。ちょっと少ないので設定変更する。再度「main.cf」を編集して最下部に追記する。
※追記する箇所のみ記載

# Maximum mailbox size 1GB. Maximum message size 20MB.
mailbox_size_limit = 1024000000
message_size_limit = 20480000
バーチャルメールボックスの設定

バーチャルメールボックスの設定をする。再度「main.cf」を編集して最下部に追記する。
※追記する箇所のみ記載

# Virtual mailbox settings.
virtual_mailbox_domains = hirohiro716.com
virtual_mailbox_base = /var/spool/mail/virtual
virtual_mailbox_maps = hash:/etc/postfix/vmailbox
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000

main.cfで指定したバーチャルメールボックスの場所を定義するファイルを作成する。

user1@hirohiro716.com hirohiro716.com/user1/Maildir/
user2@hirohiro716.com hirohiro716.com/user2/Maildir/

作成したvmailboxから検索テーブル(vmailbox.db)を生成する。

# postmap /etc/postfix/vmailbox
バーチャルエイリアスの設定

バーチャルエイリアスの設定をする。再度「main.cf」を編集して最下部に追記する。
※追記する箇所のみ記載

# Virtual ailias settings.
virtual_alias_domains = alias.hirohiro716.com
virtual_alias_maps = hash:/etc/postfix/virtual

main.cfで指定したバーチャルエイリアスの転送先を定義するファイルを作成する。

@alias.hirohiro716.com @hirohiro716.com

作成したvirtualから検索テーブル(virtual.db)を生成する。

# postmap /etc/postfix/virtual
メーリングリストの設定

メーリングリストはバーチャルエイリアスの設定で実現する。再度「main.cf」を編集して「virtual_alias_maps」に「regexp:/etc/postfix/ml」をカンマ区切りで追記する。
※変更箇所のみ記載

virtual_alias_maps = hash:/etc/postfix/virtual, regexp:/etc/postfix/ml

main.cfで指定したメーリングリストの設定を定義するファイルを作成する。

# Group1
/^group1@(hirohiro716\.com|alias\.hirohiro716\.com)$/
        user1@hirohiro716.com,
        user2@hirohiro716.com,

# Team2
/^team2@(hirohiro716\.com|alias\.hirohiro716\.com)$/
        user1@hirohiro716.com,

ファイアウォールの例外設定をする。

# firewall-cmd --permanent --add-service={smtp,smtp-submission,smtps,imaps,pop3s}
# firewall-cmd --reload

サービスを有効化して実行する。

# systemctl enable --now dovecot
# systemctl enable --now postfix

AlmaLinux8にkernel5.4をインストールする

環境

・ ディストリビューション: AlmaLinux 8.5
・ Linuxカーネル: 4.18.0-348.20.1.el8_5.x86_64

手順

ELRepoを利用してインストールを行うので、GPGキーをインポートする。

# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

ELRepoリポジトリを追加する。

# dnf install https://www.elrepo.org/elrepo-release-8.el8.elrepo.noarch.rpm

kernel-ltの中身を確認する。ltはLTSの略。

名前         : kernel-lt
バージョン   : 5.4.189
リリース     : 1.el8.elrepo
Arch         : x86_64
サイズ       : 70 k
ソース       : kernel-lt-5.4.189-1.el8.elrepo.src.rpm
リポジトリー : elrepo-kernel
概要         : The Linux kernel. (The core of any Linux-based operating system.)
URL          : https://www.kernel.org/
ライセンス   : GPLv2
説明         : The kernel-lt meta package.

kernel-ltをインストールする。

# dnf --enablerepo=elrepo-kernel install kernel-lt kernel-lt-devel kernel-lt-headers

再起動してブート時に新しくインストールしたカーネルを選択する。

# reboot

AlmaLinux8.5にリモートデスクトップで接続する

EPELリポジトリを追加する。

# dnf install epel-release

xrdpをインストールする。

# dnf install xrdp

ファイアウォールに例外を追加する。

# firewall-cmd --permanent --add-service=rdp
# firewall-cmd --reload

サービスを有効化して起動する。

# systemctl enable xrdp
# systemctl start xrdp