> 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 による登録](/ja/zheng-ming-shu-guan-li/api-certificates/api-enrollment.md)
{% endcontent-ref %}

## PowerShell モジュール SCEPmanClient

### 初回要求

Linux サーバーで証明書を要求するには、SCEPmanClient PowerShell モジュールを使用できます:

```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 モジュールを使用して、既存の証明書を更新することもできます。これにより、認証に service principal を使用する必要もなくなります:

```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 クライアント](/ja/zheng-ming-shu-guan-li/api-certificates/self-service-enrollment/unmanaged-linux-client.md)
{% endcontent-ref %}

#### 2. App Service URL

SCEPman アプリ サービスの URL。

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

#### 3. API スコープ

これは ***アプリケーション ID URI*** の ***SCEPman-api*** アプリ登録で作成できる 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 を使用してその証明書を更新します（有効期限が近い場合）。スクリプトを定期的に実行すれば、有効期限が近づいたときに証明書が更新されるようになります。これを実現するために cronjob を設定できます。以下のコマンドは、その方法の一例です。これは、コマンドを毎日（システムの電源が入っている場合）実行する cronjob と、再起動時にコマンドを実行する cronjob を設定します。

{% 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
