Debian 12 bookworm
Sponsored Link

Code Server : インストール2025/03/19

 

Visual Studio Code を自身のサーバーで実行可能な Code Server のインストールと設定です。

[1] Code Server をインストールします。
root@dlp:~#
wget https://code-server.dev/install.sh
root@dlp:~#
bash install.sh

Debian GNU/Linux 12 (bookworm)
Installing v4.98.2 of the amd64 deb package from GitHub.

+ mkdir -p ~/.cache/code-server
+ curl -#fL -o ~/.cache/code-server/code-server_4.98.2_amd64.deb.incomplete -C - https://github.com/coder/code-server/releases/download/v4.98.2/code-server_4.98.2_amd64.deb
######################################################################### 100.0%
+ mv ~/.cache/code-server/code-server_4.98.2_amd64.deb.incomplete ~/.cache/code-server/code-server_4.98.2_amd64.deb
+ dpkg -i ~/.cache/code-server/code-server_4.98.2_amd64.deb
Selecting previously unselected package code-server.
(Reading database ... 35749 files and directories currently installed.)
Preparing to unpack .../code-server_4.98.2_amd64.deb ...
Unpacking code-server (4.98.2) ...
Setting up code-server (4.98.2) ...

deb package has been installed.

To have systemd start code-server now and restart on boot:
  sudo systemctl enable --now code-server@$USER
Or, if you don't want/need a background service you can run:
  code-server

Deploy code-server for your team with Coder: https://github.com/coder/coder
[2] 任意の一般ユーザーで Code Server を起動して動作確認します。
自己署名の証明書を使用して HTTPS で他ホストからもアクセスできるように設定します。
debian@dlp:~$
systemctl --user start code-server

debian@dlp:~$
systemctl --user stop code-server

# 証明書作成

debian@dlp:~$
cd ~/.config/code-server

debian@dlp:~/.config/code-server$
openssl ecparam -name prime256v1 -genkey -out server.key

debian@dlp:~/.config/code-server$
openssl req -new -key server.key -out server.csr

You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:JP                            # 国
State or Province Name (full name) [Some-State]:Hiroshima       # 地域(県)
Locality Name (eg, city) []:Hiroshima                           # 都市
Organization Name (eg, company) [Internet Widgits Pty Ltd]:GTS  # 組織名
Organizational Unit Name (eg, section) []:Server World          # 組織の部門名
Common Name (e.g. server FQDN or YOUR name) []:dlp.srv.world    # サーバーの FQDN
Email Address []:debian@dlp.srv.world                           # 管理者アドレス

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

# サーバーの DNS 名と IP アドレスは自身の環境に置き換え

debian@dlp:~/.config/code-server$
echo 'subjectAltName = DNS:dlp.srv.world, IP:10.0.0.30' > altname.txt

debian@dlp:~/.config/code-server$
openssl x509 -in server.csr -out server.crt -req -signkey server.key -extfile altname.txt -days 3650

debian@dlp:~/.config/code-server$
vi ~/.config/code-server/config.yaml
# bind-addr : 他ホストからもアクセスする場合はリスンする IP アドレス または [0.0.0.0] (全てリスン) を指定 
# * bind-addr のポートは一般ユーザーの場合 1024 以上の任意のポートを指定可
# password : 任意のログインパスワードを指定
# cert, cert-key : 作成した証明書を指定

bind-addr: 0.0.0.0:8082
auth: password
password: mypassword01
cert: /home/debian/.config/code-server/server.crt
cert-key: /home/debian/.config/code-server/server.key

debian@dlp:~/.config/code-server$
chmod 600 ~/.config/code-server/config.yaml

debian@dlp:~/.config/code-server$
systemctl --user start code-server
[3] 任意のクライアントコンピューターで Web ブラウザーを起動し、設定した URL へアクセスします。
自己署名の証明書の場合、エラーを無視してログインしても、ログイン後のサービスワーカーの起動に失敗するため、事前に証明書をクライアントコンピューターにインストールして信頼させておきます。
証明書のフィールドをクリックして証明書を表示します。
[4] [詳細] タブに移動して [エクスポート] をクリックし、コンピューターの任意の場所へファイルを保存します。
[5] 保存したファイルをクリックして、[証明書をインストール] をクリックします。
[6] [現在のユーザー] を選択して進み、証明書のインストール先に [信頼されたルート証明機関] を選択してインストールします。
[7] 再度、設定した URL へアクセスすると、ログイン画面が表示されます。
設定したパスワードでログインできます。
[8] 正常にログインできればインストール完了です。
関連コンテンツ