Skip to content

Commit 3b88a4b

Browse files
Merge pull request #10043 from Ibnajjar/patch-1
AB#8043: Fixed Linux commands for certificate extraction and added automation through bash script.
2 parents 680888f + cdc08e2 commit 3b88a4b

File tree

1 file changed

+71
-26
lines changed

1 file changed

+71
-26
lines changed

support/system-center/scom/use-ca-certificate-on-scx-agent.md

Lines changed: 71 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Convert self-signed SCX certificates to CA certificates
33
description: Introduces how to convert a self-signed certificate on an SCX agent to a Certificate Authority (CA) signed certificate.
44
ms.date: 04/15/2024
5-
ms.reviewer: alexkre, blakedrumm, edpaca, stparker, udmudiar, v-weizhu
5+
ms.reviewer: alexkre, blakedrumm, edpaca, stparker, udmudiar, v-weizhu, v-ryanberg
66
ms.topic: how-to
77
ms.custom: linux-related-content
88
---
@@ -76,65 +76,108 @@ On a CA server in your SCOM environment, follow these steps to create a certific
7676

7777
## Copy and edit the certificate on the Unix/Linux server
7878

79+
Use one of the following methods to configure the certificate on the the Unix/Linux server:
80+
81+
### Method 1: Configure certificate manually
82+
7983
1. Copy the certificate to the Unix/Linux server for which the certificate was issued.
8084
1. Export the private key by using the following command:
8185

8286
```console
83-
openssl pkcs12 -in <FileName>.pfx -nocerts -out key.pem
87+
openssl pkcs12 -in <FileName>.pfx -nocerts -out /etc/opt/omi/ssl/omikey.pem -nodes -passin pass:"pfxpassword"
8488
```
8589

86-
While exporting the private key from the certificate store, a new password has to be set for the new key file.
87-
88-
:::image type="content" source="media/use-ca-certificate-on-scom-linux-agent/command-export-private-key.png" alt-text="Screenshot that shows the command to export the private key.":::
89-
90-
After the export is completed, you should see a *key.pem* file:
91-
92-
:::image type="content" source="media/use-ca-certificate-on-scom-linux-agent/command-get-key-dot-pem-file.png" alt-text="Screenshot that shows the command to get the private key file.":::
90+
While exporting the private key from the certificate store, include the `-nodes` paramter (which stands for no Desktop Environments (DEs)). This instructs OpenSSL to output the private key in an unencrypted format. Otherwise a new password has to be set for the new key file.
9391

9492
1. Export the certificate by using the following command:
9593

9694
```console
97-
openssl pkcs12 -in <FileName>.pfx -clcerts -nokeys -out omi.pem
95+
openssl pkcs12 -in <FileName>.pfx -clcerts -nokeys -out /etc/opt/omi/ssl/omi-host-$(hostname).pem -passin pass:"pfxpassword"
9896
```
9997

100-
While exporting the certificate from the certificate store, you have to enter the password for the *\<FileName>.pfx* file.
98+
1. Delete and create a new symbolic link:
10199

102-
:::image type="content" source="media/use-ca-certificate-on-scom-linux-agent/command-export-certificate.png" alt-text="Screenshot that shows the command to export the certificate.":::
100+
```console
101+
rm -f /etc/opt/omi/ssl/omi.pem
102+
ln -s /etc/opt/omi/ssl/omi-host-$(hostname).pem /etc/opt/omi/ssl/omi.pem
103+
```
104+
105+
1. Set the correct permissions and ownership on the private key, certificate, and symbolic link:
103106

104-
After the export is completed, you should see an *omi.pem* file:
107+
```console
108+
chmod 600 /etc/opt/omi/ssl/omikey.pem
109+
chmod 640 /etc/opt/omi/ssl/omi-host-$(hostname).pem /etc/opt/omi/ssl/omi.pem
110+
chown omi:omi /etc/opt/omi/ssl/omikey.pem
111+
chown root:omi /etc/opt/omi/ssl/omi-host-$(hostname).pem /etc/opt/omi/ssl/omi.pem
112+
```
105113

106-
:::image type="content" source="media/use-ca-certificate-on-scom-linux-agent/command-get-omi-dot-pem-file.png" alt-text="Screenshot that shows the command to get the certificate file.":::
114+
1. Restart the SCX agent by running the following command:
107115

108-
1. Remove the password from the private key by using the following command:
116+
```console
117+
scxadmin -restart
118+
```
119+
120+
1. Make sure the Open Management Infrastructure (OMI) processes are running after restarting the agent:
109121

110122
```console
111-
openssl rsa -in key.pem -out omikey.pem
123+
ps -ef | grep omi | grep -v grep
112124
```
113125

114-
:::image type="content" source="media/use-ca-certificate-on-scom-linux-agent/command-remove-password-from-private-key.png" alt-text="Screenshot that shows the command to remove password from the private key.":::
126+
:::image type="content" source="media/use-ca-certificate-on-scom-linux-agent/command-validate-omi-processes.png" alt-text="Screenshot that shows the command to validate omi processes running." lightbox="media/use-ca-certificate-on-scom-linux-agent/command-validate-omi-processes.png":::
115127

116-
This action is needed since the Linux agent doesn't know the password for the file.
128+
### Method 2: Configure certificate with bash script
117129

118-
1. Move the *omikey.pem* file to the Open Management Infrastructure (OMI) directory by using the following command:
130+
1. Save the following bash script: `extract_scx_cert.sh`
119131

120132
```console
121-
mv omikey.pem /etc/opt/omi/ssl/omikey.pem
133+
#!/bin/bash
134+
135+
# Usage: sudo ./extract_scx_cert.sh /path/to/certificate.pfx <pfx_password>
136+
137+
PFX_FILE="$1"
138+
PFX_PASS="$2"
139+
SSL_DIR="/etc/opt/omi/ssl"
140+
KEY_FILE="$SSL_DIR/omikey.pem"
141+
CERT_FILE="$SSL_DIR/omi-host-$(hostname).pem"
142+
SYMLINK_FILE="$SSL_DIR/omi.pem"
143+
144+
if [[ -z "$PFX_FILE" || -z "$PFX_PASS" ]]; then
145+
echo "Usage: $0 /path/to/certificate.pfx <pfx_password>"
146+
exit 1
147+
fi
148+
149+
echo "Extracting private key..."
150+
openssl pkcs12 -in "$PFX_FILE" -nocerts -out "$KEY_FILE" -nodes -passin pass:"$PFX_PASS"
151+
152+
echo "Extracting certificate..."
153+
openssl pkcs12 -in "$PFX_FILE" -clcerts -nokeys -out "$CERT_FILE" -passin pass:"$PFX_PASS"
154+
155+
echo "Creating symbolic link..."
156+
rm -f "$SYMLINK_FILE"
157+
ln -s "$CERT_FILE" "$SYMLINK_FILE"
158+
159+
echo "Setting permissions..."
160+
chmod 600 "$KEY_FILE"
161+
chmod 640 "$CERT_FILE" "$SYMLINK_FILE"
162+
chown root:omi "$CERT_FILE" "$SYMLINK_FILE"
163+
chown omi:omi "$KEY_FILE"
164+
165+
echo "Restarting omid service..."
166+
systemctl restart omid
122167
```
123168

124-
1. Restart the SCX agent by using the following command:
169+
1. Change the script permissions to be run:
125170

126171
```console
127-
scxadmin -restart
172+
chmod +x /home/user/extract_scx_cert.sh
128173
```
129174

130-
1. Make sure the *omi* processes are running after restarting the agent:
175+
1. Run the following command to run the script with these two parameters: the path to the PFX file and the password for it.
131176

132177
```console
133-
ps -ef | grep omi | grep -v grep
178+
sudo ./extract_scx_cert.sh /path/to/certificate.pfx pfx_password
134179
```
135180

136-
:::image type="content" source="media/use-ca-certificate-on-scom-linux-agent/command-validate-omi-processes.png" alt-text="Screenshot that shows the command to validate omi processes running." lightbox="media/use-ca-certificate-on-scom-linux-agent/command-validate-omi-processes.png":::
137-
138181
## Validate that the certificate is signed by the CA
139182

140183
1. Run the following command on the agent to verify that the certificate is signed by the CA:
@@ -159,6 +202,8 @@ On a CA server in your SCOM environment, follow these steps to create a certific
159202
notAfter=Jul 25 12:12:14 2033 GMT
160203
```
161204

205+
> The path `/etc/opt/microsoft/scx/ssl` contains a symbolic link `scx.pem -> /etc/opt/omi/ssl/omi.pem` that's used by the SCX agent in order to use the OMI certificate created earlier.
206+
162207
1. Run a network trace on one of the management servers/gateways in the UNIX/Linux resource pool.
163208
1. Run the following `WinRM` command against the agent and make sure you get the instance output:
164209

0 commit comments

Comments
 (0)