> For the complete documentation index, see [llms.txt](https://docs.scepman.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.scepman.com/ja/zheng-ming-shu-guan-li/api-certificates/api-enrollment/linux-server.md).

# Linux サーバー

{% hint style="info" %}
この機能には、次のバージョンが必要です。 **2.3.689** 以上。
{% endhint %}

{% hint style="warning" %}
SCEPman Enterprise Edition のみ
{% endhint %}

SCEPmanの他のユースケースでは、ユーザーを対話形式で認証し、そのユーザーが自分のアカウントまたはデバイス用のユーザー証明書のみを登録できるようにします。一方、任意のサブジェクトの証明書を非対話形式で登録したい場合もあるでしょう。

これを実現するには、サービス プリンシパルを認証し、SCEPmanのEnrollment REST APIを利用できるようにします。

## 前提条件

認証に使用できるサービス プリンシパルの作成方法については、「API Enrollment」の記事を参照してください。

{% content-ref url="/pages/36cc2f22559c6d88af378786d530d4c19b4503b4" %}
[API 登録](https://docs.scepman.com/ja/zheng-ming-shu-guan-li/api-certificates/api-enrollment.md)
{% endcontent-ref %}

## PowerShell モジュール SCEPmanClient

### 初回リクエスト

SCEPmanClient PowerShell モジュールを使用すると、Linux サーバーから証明書を要求できます。

```powershell
$Parameters = @{
    'Url'              = 'scepman.contoso.com'
    'ClientId'         = '569fbf51-aa63-4b5c-8b26-ebbcfcde2715'
    'TenantId'         = '8aa3123d-e76c-42e2-ba3c-190cabbec531'
    'ClientSecret'     = 'csa8Q~aVaWCLZTzswIBGvhxUiEvhptuqEyJugb70'
    'Subject'          = 'CN=LinuxServer'
    'IP'               = '10.22.11.8'
    'ExtendedKeyUsage' = 'ServerAuth'
    'SaveToFolder'     = '/etc/ssl/scepman'
    'IncludeRootCA'    = $true
}

New-SCEPmanCertificate @Parameters
```

### 証明書の更新

PowerShell モジュールを使用して、既存の証明書を更新することもできます。この場合、認証にサービス プリンシパルを使用する必要もありません。

```powershell
$Parameters = @{
    'CertificateFromFile' = '/home/user/.certs/server.pem'
    'KeyFromFile'         = '/home/user/.certs/server.key'
    'SaveToFolder'        = '/home/user/.certs'
}

New-SCEPmanCertificate @Parameters
```

## 登録および更新スクリプト

PowerShell モジュールを使用できない場合は、 [enrollrenewcertificate.sh](https://github.com/scepman/csr-request/blob/main/enroll-certificate/enrollrenewcertificate.sh) スクリプトを使用して、証明書を初回取得し、検証するとともに、有効期限が近づいた場合に更新を試みることができます。

### クライアントの前提条件

Enrollment REST APIを使用するには、実行するクライアント／ホストに次の前提条件が必要です。

#### [**Azure CLI**](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli) **（バージョン 2.61 以降）**

Azure CLIは、登録ユーザーを認証して登録資格を確認し、アクセストークンを取得するために使用されます。

#### cURL

作成したCSRをSCEPman Enrollment APIエンドポイントに送信し、証明書を受け取るために使用します。

#### OpenSSL

OpenSSLは、証明書の登録または更新に使用する秘密鍵とCSRを生成するために使用されます。

例:

{% code overflow="wrap" %}

```bash
./enrollrenewcertificate.sh -s https://scepman.contoso.net/ api://a7a1d6c8-51b9-48ec-9ca0-a363dc2c8436 ~/certs/ "myCertificate" "myKeyName" 30 edbc406b-7384-414e-af8b-1a3b187b3f7e [Client_Secret] 736e80bb-3102-479b-83ba-e45c80ef723b "/CN=SubjectName,O=Organization" "DNS:webserver.contoso.com"
```

{% endcode %}

#### 1. コマンド

スクリプトの動作を指定します

このユースケースでは、次のオプションを使用できます。

**-s** サーバー証明書用。初回登録か更新かを自動検出します

**-y** サーバー証明書の初回登録用

**-c** 既存の証明書署名要求を送信する場合に使用します

クライアント認証のユースケースについては、次を参照してください。

{% content-ref url="/pages/4e9d5d42c2b436d13f4197768cc3e056d7a1e22b" %}
[管理対象外の Linux クライアント](https://docs.scepman.com/ja/zheng-ming-shu-guan-li/api-certificates/self-service-enrollment/unmanaged-linux-client.md)
{% endcontent-ref %}

#### 2. App Service URL

SCEPman App Service の URL。

*例: "<https://scepman.contoso.net/>"*

#### 3. API スコープ

これは、 ***Application ID URI*** の ***SCEPman-api*** 環境内のアプリ登録です。

*例: "api://a7a1d6c8-51b9-48ec-9ca0-a363dc2c8436"*

<figure><img src="https://114237723-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LoGejQeUQcw7lqnQ3WX%2Fuploads%2FtjlK9CzLeLcLmbu0nK3b%2Fimage.png?alt=media&amp;token=a7af923f-c790-416e-bb9d-9e640d391c44" alt=""><figcaption></figcaption></figure>

#### 4. 証明書のファイル名

作成または更新時に読み込む証明書のファイル名（拡張子なし）。

*例: "myCertificate"*

#### 5. 証明書のディレクトリ

証明書を作成する、または更新を試みるディレクトリ。

*例: \~/certs/*

#### 8. 更新しきい値

証明書の有効期限が何日以内に迫ったら、スクリプトが更新処理を開始するかを指定します。

*例: 30*

### *サーバー証明書の追加パラメーター:*

#### 9. Service Principal のクライアント ID

認証に使用するアプリ登録のアプリケーション（クライアント）ID。

#### 10. Service Principal のクライアント シークレット

認証に使用するアプリ登録で作成したクライアント シークレット。

#### 11. Service Principal の Tenant ID

アプリ登録の Tenant ID。

#### 12. 証明書のサブジェクト

証明書の登録に使用するサブジェクト。

*形式: /CN=SubjectName,O=Organization*

#### 13. 証明書の拡張機能

これはサブジェクト代替名として追加されます。

*例: DNS:webserver.contoso.com*

### *CSR 署名の使用例（-c コマンド）*

{% code overflow="wrap" %}

```bash
# 秘密鍵を生成
openssl genrsa -out myKey.rsa 4096

# クライアント認証用のユーザー証明書の CSR を作成
openssl req -new -key myKey.rsa -sha256 -out myCSR -subj "/CN=John Smith" -addext "subjectAltName=otherName:1.3.6.1.4.1.311.20.2.3;UTF8:john.smith@contoso.net" -addext "extendedKeyUsage=1.3.6.1.5.5.7.3.2"

./enrollrenewcertificate.sh -c https://scepman.contoso.net/ api://a7a1d6c8-51b9-48ec-9ca0-a363dc2c8436 ~/certs "myCertificate" myKey.rsa 30 edbc406b-7384-414e-af8b-1a3b187b3f7e [Client_Secret] 736e80bb-3102-479b-83ba-e45c80ef723b myCSR

```

{% endcode %}

#### 考慮事項

* このスクリプトは生成した鍵を暗号化しません（暗号化にはパスフレーズの入力が必要なため、自動更新を可能にする目的で暗号化を省略しています）。
* Certificate Master のパスフレーズで保護された証明書を更新する場合は、更新時にこのパスフレーズを入力する必要があります。

## 自動更新を設定する

上記の bash スクリプトを実行すると、証明書がすでに登録されていることを検出した場合、mTLS を使用して証明書を更新します（有効期限が近い場合）。スクリプトを定期的に実行すれば、有効期限が近づいたときに証明書が更新されます。これを実現するには cron ジョブを設定できます。以下のコマンドは設定例です。システムの電源が入っている場合にコマンドを毎日実行する cron ジョブと、再起動時にコマンドを実行する cron ジョブを設定します。

{% code overflow="wrap" %}

```
(crontab -l ; echo @daily /path/to/enrollrenewcertificate.sh -s https://scepman.contoso.net/ api://a7a1d6c8-51b9-48ec-9ca0-a363dc2c8436 /path/to/certs "myCertificate" "myKeyName" 30 edbc406b-7384-414e-af8b-1a3b187b3f7e [Client_Secret] 736e80bb-3102-479b-83ba-e45c80ef723b "/CN=SubjectName,O=Organization" "DNS:webserver.contoso.com" ; echo @reboot /path/to/enrollrenewcertificate.sh -s https://scepman.contoso.net/ api://a7a1d6c8-51b9-48ec-9ca0-a363dc2c8436 /path/to/certs "myCertificate" "myKeyName" 30 edbc406b-7384-414e-af8b-1a3b187b3f7e [Client_Secret] 736e80bb-3102-479b-83ba-e45c80ef723b "/CN=SubjectName,O=Organization" "DNS:webserver.contoso.com") | crontab -
```

{% endcode %}

Cron が実行するコマンドは、スクリプトや証明書のあるディレクトリから実行されるとは限らないため、スクリプトや証明書には絶対パスを指定することが重要です。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.scepman.com/ja/zheng-ming-shu-guan-li/api-certificates/api-enrollment/linux-server.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
