<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>コンピュータ | My Interests</title>
	<atom:link href="https://ds.machijun.net/category/%E3%82%B3%E3%83%B3%E3%83%94%E3%83%A5%E3%83%BC%E3%82%BF/feed/" rel="self" type="application/rss+xml" />
	<link>https://ds.machijun.net/</link>
	<description>残したいことを残していきます</description>
	<lastBuildDate>Sun, 19 May 2019 15:31:25 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.9.14</generator>
	<item>
		<title>WordPressで数式を表示しよう(MathJax)</title>
		<link>https://ds.machijun.net/wordpress%e3%81%a7%e6%95%b0%e5%bc%8f%e3%82%92%e8%a1%a8%e7%a4%ba%e3%81%97%e3%82%88%e3%81%86mathjax/</link>
		<pubDate>Sat, 01 Dec 2018 08:40:38 +0000</pubDate>
		<dc:creator><![CDATA[jun]]></dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[mathjax]]></category>
		<category><![CDATA[quicklatex]]></category>
		<category><![CDATA[tex]]></category>
		<category><![CDATA[数式]]></category>

		<guid isPermaLink="false">https://machijun.net/?p=2521</guid>
		<description><![CDATA[<p>WordPressで数式を表示しよう このブログのように、理系ネタが多いブログでは数式の表示が必須です。 今回はWordPressで数式を表現する方法、とりわけMathJaxについて紹介します。 数式の表現の方法とメリッ [&#8230;]</p>
<p>The post <a href="https://ds.machijun.net/wordpress%e3%81%a7%e6%95%b0%e5%bc%8f%e3%82%92%e8%a1%a8%e7%a4%ba%e3%81%97%e3%82%88%e3%81%86mathjax/">WordPressで数式を表示しよう(MathJax)</a> first appeared on <a href="https://ds.machijun.net/">My Interests</a>.</p>]]></description>
				<content:encoded><![CDATA[<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS_CHTML" type="text/javascript">    
    MathJax.Hub.Config({
        HTML: ["input/TeX","output/HTML-CSS"],
        TeX: {
               Macros: {
                        bm: ["\\boldsymbol{#1}", 1],
                        argmax: ["\\mathop{\rm arg\,max}\limits"],
                        argmin: ["\\mathop{\rm arg\,min}\limits"]},
						
               extensions: ["AMSmath.js","AMSsymbols.js","color.js"],
               equationNumbers: { autoNumber: "AMS" } },
        extensions: ["tex2jax.js"],
        jax: ["input/TeX","output/HTML-CSS"],
        tex2jax: { inlineMath: [ ['$','$'], ["\\(","\\)"] ],
                   displayMath: [ ['$$','$$']], 
                   processEscapes: true },
        "HTML-CSS": { availableFonts: ["TeX"],
                      linebreaks: { automatic: true } }
    });
</script>

$\newcommand{\lnl}{\\[8pt]}$
$\newcommand{\Lnl}{\\[18pt]}$
$\newcommand{\delt}{\mathrm{d}}$
$\newcommand{\comb}{\mathrm{C}}$
$\DeclareMathOperator*{\ssum}{\Sigma}$
$\DeclareMathOperator*{\sprod}{\Pi}$
<h2>WordPressで数式を表示しよう</h2>
<p>このブログのように、理系ネタが多いブログでは数式の表示が必須です。<br />
今回はWordPressで数式を表現する方法、とりわけMathJaxについて紹介します。<br />
<span id="more-2521"></span><br />
<p class="ad-label">スポンサーリンク</p>
<div class="ad-innercontents">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- machijun.net-incontent -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-0727807216839004"
     data-ad-slot="9340959476"
     data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
</p>
<h2>数式の表現の方法とメリット・デメリット</h2>
<p>数式の表現の方法としては、</p>
<ol>
<li>がんばって文字で表現する</li>
<li>LaTeXで数式を作り画像を張り付ける</li>
<li>LaTeXでPDFを作りファイルをダウンロードしてもらう</li>
<li>QuickLaTeXを使ってTeX数式を画像に変換する</li>
<li>MathJaxを使ってTeX数式を変換する</li>
</ol>
<p>などなど、いろいろあります。</p>
<p>①については、論外です。<br />
例えば、2次方程式の解の公式<br />
<div style="overflow-x: auto;">\begin{align}x = \frac{-b\pm \sqrt{b^2-4ac}}{2a}\end{align}</div><br />
を文字だけで表現しようとすると次のようになります。</p>
<p><strong>x = (-b ± √(b^2-4ac))/(2a)</strong></p>
<p>これ、書くほうもめんどくさいですし、見るほうもわかりにくいですよね。<br />
数式の中身の理解に時間をとるべきで、表現の読み解きに時間を割くべきではないです。</p>
<p>②については、量が多いと数式の作成・貼り付けなど手間がかかります。<br />
加筆修正する際にも、再度画像を作成する必要があるなど、管理も大変です。<br />
うちのブログのようなほとんど数式みたいなところには向きません。</p>
<p>③はよくある選択だと思います。<br />
ただ、数式を表現したいだけなのに全体をLaTeX（PDF）にするのはいかがなものでしょうか。<br />
ページの表現はWordPressのようなCMSを使ってうまくやりたいですよね。<br />
PDFファイルの中身はWordPressの検索にヒットしません。</p>
<p>また、これも加筆修正の際にTeXソースを探してきて、修正して、PDF化して、アップロードして、と手間がかかります。<br />
これだけ手間だと、ちょっとした間違いだと放置しちゃいがちになっちゃいますよね。</p>
<p>④当サイトはもともとこれでした。<br />
理由は、WordPress上で編集できて、結果をすぐに見れるからです。<br />
またMathJaxの描画の遅さが気になって、画像化できているほうが早いだろうという目論見があったからです。</p>
<p>しかし、使っているうちに、</p>
<ul>
<li>キャッシュがないときの画像生成がめちゃくちゃ遅い</li>
<li>日本語が使えない</li>
<li>画像が荒いことがある</li>
</ul>
<p>ここらへんの欠点が目に付くようになってしまいました。</p>
<p>⑤MathJaxもWordPress上で編集でき、結果をすぐに見れる利点は④と同様です。<br />
描画の遅さも1ページに表示する数式を極力抑えることで解決できます。<br />
日本語も使えますし、デバイスに合わせて表示するのでどのデバイスで見ても綺麗に表現できます。<br />
今回は、MathJaxをWordPressに組み込む方法を紹介します。</p>
<p>同じ数式をQuickLaTeXとMathJaxで表現すると、<br />
QuickLaTeXバージョン<br />
<img alt='' class='alignnone size-full wp-image-2825 ' src='https://imgds.machijun.net/wp-content/uploads/2018/12/07015821/img_5c09552d1b2cb.png' /></p>
<p><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS_CHTML" type="text/javascript">    
    MathJax.Hub.Config({
        HTML: ["input/TeX","output/HTML-CSS"],
        TeX: {
               Macros: {
                        bm: ["\\boldsymbol{#1}", 1],
                        argmax: ["\\mathop{\rm arg\,max}\limits"],
                        argmin: ["\\mathop{\rm arg\,min}\limits"]},
						
               extensions: ["AMSmath.js","AMSsymbols.js","color.js"],
               equationNumbers: { autoNumber: "AMS" } },
        extensions: ["tex2jax.js"],
        jax: ["input/TeX","output/HTML-CSS"],
        tex2jax: { inlineMath: [ ['$','$'], ["\\(","\\)"] ],
                   displayMath: [ ['$$','$$']], 
                   processEscapes: true },
        "HTML-CSS": { availableFonts: ["TeX"],
                      linebreaks: { automatic: true } }
    });
</script>

$\newcommand{\lnl}{\\[8pt]}$
$\newcommand{\Lnl}{\\[18pt]}$
$\newcommand{\delt}{\mathrm{d}}$
$\newcommand{\comb}{\mathrm{C}}$
$\DeclareMathOperator*{\ssum}{\Sigma}$
$\DeclareMathOperator*{\sprod}{\Pi}$<br />
mathjaxバージョン<br />
<div style="overflow-x: auto;">\begin{align*}<br />
\pi(x) = \sum_{m \le \log_2 x} \frac{\mu(m)}{m} \left(\mathrm{li}(x^\frac{1}{m}) &#8211; \sum_{\rho} \mathrm{li}(x^{\frac{\rho}{m}}) &#8211; \log 2 + \int_{x^{\frac{1}{m}}}^\infty \frac{\mathrm{d} t}{t(t^2-1)\log t}\right)<br />
\end{align*}</div></p>
<p>どっちが綺麗か一目瞭然ですよね。</p>
<h2>MathJaxをWordPressに導入しよう</h2>
<p>MathJaxをWordPressに導入するためには、プラグインを使うのが王道のようですが、ずっとメンテナンスされていないようです。<br />
ここでは、JavaScriptを使って導入する方法を紹介します。</p>
<h3>まずは導入</h3>
<p>MathJaxを導入するのはとても簡単です。<br />
下記コードを数式を使う前に記載するだけです。</p>
<pre class="brush: xml; title: ; notranslate">
&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS_CHTML&quot; type=&quot;text/javascript&quot;&gt;    
    MathJax.Hub.Config({
        HTML: [&quot;input/TeX&quot;,&quot;output/HTML-CSS&quot;],
        TeX: {
               Macros: {
                        bm: [&quot;\\boldsymbol{#1}&quot;, 1]},
               extensions: [&quot;AMSmath.js&quot;,&quot;AMSsymbols.js&quot;,&quot;color.js&quot;],
               equationNumbers: { autoNumber: &quot;AMS&quot; } },
        extensions: [&quot;tex2jax.js&quot;],
        jax: [&quot;input/TeX&quot;,&quot;output/HTML-CSS&quot;],
        tex2jax: { inlineMath: [ ['$','$'], [&quot;\\(&quot;,&quot;\\)&quot;] ],
                   displayMath: [ ['$$','$$']], 
                   processEscapes: true },
        &quot;HTML-CSS&quot;: { availableFonts: [&quot;TeX&quot;],
                      linebreaks: { automatic: true } }
    });
&lt;/script&gt;
</pre>
<p>途中に改行など入れてしまうと自動的にWordPressに整形され意図通りにならないことがありますので、注意ください。<br />
上記を書いたあとに、記事中にTeX形式で次のように書くと該当部分が数式化されます。<br />
（事情によりアスタリスクを全角で書いています。実際は半角で記載ください。）</p>
<pre class="brush: xml; title: ; notranslate">
二次方程式$ax^2+bx+c=0(a\neq 0)$の解の公式は、
\begin{align＊}
x = \frac{-b\pm\sqrt{b^2-4ac}}{2a}
\end{align＊}
</pre>
<div>
<div class="box30">
<div class="box-title">上記の出力結果例</div>
<div>
二次方程式$ax^2+bx+c=0(a\neq 0)$の解の公式は、<br />
<div style="overflow-x: auto;">\begin{align*}<br />
x = \frac{-b\pm\sqrt{b^2-4ac}}{2a}<br />
\end{align*}</div>
</div>
</div>
</div>
<p>簡単ですね。</p>
<h3>コードスニペット(ショートコード)化</h3>
<p>毎回、上記のようにスクリプトを張り付けるのは大変です。<br />
スニペット化しましょう。<br />
私は<a href="https://wordpress.org/plugins/code-snippets/" rel="noopener" target="_blank">Code Snippets</a>というプラグインを使っています。<br />
導入の仕方は他の記事に譲って、MathJaxを使うためのスニペットについて解説します。</p>
<p>①WordPressの管理画面からSnippets→「Add New」を選択します。<br />
<img alt='' class='alignnone size-full wp-image-2822 ' src='https://imgds.machijun.net/wp-content/uploads/2018/12/07015734/img_5c0954fe756a3.png' /></p>
<p>②Add New Snippetのページが表示されます。<br />
<img alt='' class='alignnone size-full wp-image-2824 ' src='https://imgds.machijun.net/wp-content/uploads/2018/12/07015800/img_5c0955182fb84.png' /></p>
<p>Titleの部分は好きに書いてください「例：MathJax利用コードスニペット」<br />
Codeの部分に次のように書いてください。</p>
<pre class="brush: php; title: ; notranslate">
function MathJax_code(){
return &lt;&lt;&lt;EOD
&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS_CHTML&quot; type=&quot;text/javascript&quot;&gt;    
    MathJax.Hub.Config({
        HTML: [&quot;input/TeX&quot;,&quot;output/HTML-CSS&quot;],
        TeX: {
               Macros: {
                        bm: [&quot;\\\\boldsymbol{#1}&quot;, 1]},
               extensions: [&quot;AMSmath.js&quot;,&quot;AMSsymbols.js&quot;,&quot;color.js&quot;],
               equationNumbers: { autoNumber: &quot;AMS&quot; } },
        extensions: [&quot;tex2jax.js&quot;],
        jax: [&quot;input/TeX&quot;,&quot;output/HTML-CSS&quot;],
        tex2jax: { inlineMath: [ ['$','$'], [&quot;\\\\(&quot;,&quot;\\\\)&quot;] ],
                   displayMath: [ ['$$','$$']], 
                   processEscapes: true },
        &quot;HTML-CSS&quot;: { availableFonts: [&quot;TeX&quot;],
                      linebreaks: { automatic: true } }
    });
&lt;/script&gt;

EOD;
}
add_shortcode('usemath','MathJax_code');
</pre>
<p>③「Save Changes and Activate」ボタンを押して登録してください。</p>
<p>④数式を使いたい記事で、次のように[usemath]を記載してから先ほどと同様にTeX形式を使うことができます。</p>
<pre class="brush: xml; title: ; notranslate">
[usemath]
二次方程式$ax^2+bx+c=0(a\neq 0)$の解の公式は、
\begin{align＊}
x = \frac{-b\pm\sqrt{b^2-4ac}}{2a}
\end{align＊}
</pre>
<h3>スマホ対応(横スクロール対応)する</h3>
<p>これで気持ちよく数式を書く環境が整ったと思います。<br />
しかし、スマホから数式入りのページを見るとどうでしょう。<br />
長い数式がはみ出てかっこ悪いですね。</p>
<p>そこで、長い数式を横スクロールできるようにしましょう。</p>
<h4>手作業</h4>
<p>長い数式を</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div style=&quot;overflow-x: auto;&quot;&gt;長い数式&lt;/div&gt;
</pre>
<p>のように、overflow-x:auto;スタイルを付けたdivで囲むことで簡単に横スクロール対応できます。<br />
はみ出すほど長くない場合は、このスタイルは無視されます。</p>
<p>しかし、全てをこのように囲むのは大変です。<br />
はみ出すやつのみ囲もうと思っても、たまたま自分のスマホでははみ出さなかったら、対応漏れしそうですね。<br />
そこで自動化を考えます。</p>
<h4>自動化</h4>
<p>先ほどのスニペットをこのように書き換えます。</p>
<pre class="brush: php; title: ; notranslate">
function MathJax_code(){
return &lt;&lt;&lt;EOD
&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS_CHTML&quot; type=&quot;text/javascript&quot;&gt;    
    MathJax.Hub.Config({
        HTML: [&quot;input/TeX&quot;,&quot;output/HTML-CSS&quot;],
        TeX: {
               Macros: {
                        bm: [&quot;\\\\boldsymbol{#1}&quot;, 1]},
               extensions: [&quot;AMSmath.js&quot;,&quot;AMSsymbols.js&quot;,&quot;color.js&quot;],
               equationNumbers: { autoNumber: &quot;AMS&quot; } },
        extensions: [&quot;tex2jax.js&quot;],
        jax: [&quot;input/TeX&quot;,&quot;output/HTML-CSS&quot;],
        tex2jax: { inlineMath: [ ['$','$'], [&quot;\\\\(&quot;,&quot;\\\\)&quot;] ],
                   displayMath: [ ['$$','$$']], 
                   processEscapes: true },
        &quot;HTML-CSS&quot;: { availableFonts: [&quot;TeX&quot;],
                      linebreaks: { automatic: true } }
    });
&lt;/script&gt;

EOD;
}
function change_math_into_div($text){
    $replace = array(
        //'変更前' =&gt; '変更後',
        '<div style="overflow-x: auto;">\begin{align}' =&gt; '&lt;div style=&quot;overflow-x: auto;&quot;&gt;<div style="overflow-x: auto;">\begin{align}',
        '\end{align}</div>' =&gt; '\end{align}</div>&lt;/div&gt;',
        '<div style="overflow-x: auto;">\begin{align*}' =&gt; '&lt;div style=&quot;overflow-x: auto;&quot;&gt;<div style="overflow-x: auto;">\begin{align*}',
        '\end{align*}</div>' =&gt; '\end{align*}</div>&lt;/div&gt;',  

    );
    $text = str_replace(array_keys($replace), $replace, $text);
    return $text;
}
add_filter('the_content', 'change_math_into_div');
add_shortcode('usemath','MathJax_code');
</pre>
<p>これは、簡単に言うと記事本文中の文字列を置き換えてくれるというものです。<br />
横に長くなる数式は￥begin{align}￥end{align}で囲むようにすれば、対応忘れなく横スクロール可能になります。</p>
<h2>まとめ</h2>
<p>以上、WordPressで数式を表現する方法でした。<br />
参考にしていただければ幸いです。</p><p>The post <a href="https://ds.machijun.net/wordpress%e3%81%a7%e6%95%b0%e5%bc%8f%e3%82%92%e8%a1%a8%e7%a4%ba%e3%81%97%e3%82%88%e3%81%86mathjax/">WordPressで数式を表示しよう(MathJax)</a> first appeared on <a href="https://ds.machijun.net/">My Interests</a>.</p>]]></content:encoded>
			</item>
		<item>
		<title>游フォントをWindows7にインストールする</title>
		<link>https://ds.machijun.net/%e6%b8%b8%e3%83%95%e3%82%a9%e3%83%b3%e3%83%88%e3%82%92windows7%e3%81%ab%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%bc%e3%83%ab%e3%81%99%e3%82%8b/</link>
		<pubDate>Mon, 30 Apr 2018 13:59:15 +0000</pubDate>
		<dc:creator><![CDATA[jun]]></dc:creator>
				<category><![CDATA[コンピュータ]]></category>

		<guid isPermaLink="false">https://machijun.net/?p=1967</guid>
		<description><![CDATA[<p>游フォントとは Office2016では游フォントがデフォルトになっています。 Windows7または8でOffice2010/2013がインストールされていれば游フォントを無料でインストールすることができます。 誰かが [&#8230;]</p>
<p>The post <a href="https://ds.machijun.net/%e6%b8%b8%e3%83%95%e3%82%a9%e3%83%b3%e3%83%88%e3%82%92windows7%e3%81%ab%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%bc%e3%83%ab%e3%81%99%e3%82%8b/">游フォントをWindows7にインストールする</a> first appeared on <a href="https://ds.machijun.net/">My Interests</a>.</p>]]></description>
				<content:encoded><![CDATA[<h2>游フォントとは</h2>
<p>Office2016では游フォントがデフォルトになっています。<br />
Windows7または8でOffice2010/2013がインストールされていれば游フォントを無料でインストールすることができます。<br />
誰かが作った資料が游フォントを使っている可能性があるので、インストールしておいて損はありません。<br />
<span id="more-1967"></span><br />
<p class="ad-label">スポンサーリンク</p>
<div class="ad-innercontents">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- machijun.net-incontent -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-0727807216839004"
     data-ad-slot="9340959476"
     data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
</p>
<h2>インストールできる条件</h2>
<p>ダウンロードページのシステム要件に以下のように書かれています。</p>
<blockquote><p>サポートされるオペレーティング システム<br />
Windows 7, Windows 8<br />
Office 2013/2010, Windows 8/7</p></blockquote>
<p>これから、解釈すると以下の表のOKに該当する人がインストール権利を持っていると考えられます。</p>
<table>
<tbody>
<tr>
<td style="background-color: #cccccc; text-align: center;"></td>
<td style="background-color: #cccccc; text-align: center;"><strong>Office2010より前 or Office無</strong></td>
<td style="background-color: #cccccc; text-align: center;"><strong>Office2010</strong></td>
<td style="background-color: #cccccc; text-align: center;"><strong>Office2013</strong></td>
<td style="background-color: #cccccc; text-align: center;"><strong>Office2016</strong></td>
</tr>
<tr>
<td style="background-color: #cccccc; text-align: center;"><strong>Windows7</strong></td>
<td style="text-align: center;">NG</td>
<td style="background-color: #c9dfff; text-align: center;">OK</td>
<td style="background-color: #c9dfff; text-align: center;">OK</td>
<td style="text-align: center;">不要</td>
</tr>
<tr>
<td style="background-color: #cccccc; text-align: center;"><strong>Windows8</strong></td>
<td style="text-align: center;">NG※</td>
<td style="background-color: #c9dfff; text-align: center;">OK</td>
<td style="background-color: #c9dfff; text-align: center;">OK</td>
<td style="text-align: center;">不要</td>
</tr>
<tr>
<td style="background-color: #cccccc; text-align: center;"><strong>Windows8.1</strong></td>
<td style="text-align: center;">不要</td>
<td style="text-align: center;">不要</td>
<td style="text-align: center;">不要</td>
<td style="text-align: center;">不要</td>
</tr>
<tr>
<td style="background-color: #cccccc; text-align: center;"><strong>Windows10</strong></td>
<td style="text-align: center;">不要</td>
<td style="text-align: center;">不要</td>
<td style="text-align: center;">不要</td>
<td style="text-align: center;">不要</td>
</tr>
</tbody>
</table>
<p>※は今回の方法ではNGですが、Windows8.1にアップグレードすることで游フォントを使うことができます。</p>
<h2>ダウンロードとインストール</h2>
<p>ダウンロードとインストールはとっても簡単です。<br />
マイクロソフトの<a href="https://www.microsoft.com/ja-jp/download/confirmation.aspx?id=49116" target="_blank" rel="noopener">公式ページ</a>からインストーラーを入手してインストールするだけです。</p><p>The post <a href="https://ds.machijun.net/%e6%b8%b8%e3%83%95%e3%82%a9%e3%83%b3%e3%83%88%e3%82%92windows7%e3%81%ab%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%bc%e3%83%ab%e3%81%99%e3%82%8b/">游フォントをWindows7にインストールする</a> first appeared on <a href="https://ds.machijun.net/">My Interests</a>.</p>]]></content:encoded>
			</item>
		<item>
		<title>Let&#8217;s Encryptで作った証明書をリモートデスクトップの証明書に使う</title>
		<link>https://ds.machijun.net/lets-encrypt%e3%81%a7%e4%bd%9c%e3%81%a3%e3%81%9f%e8%a8%bc%e6%98%8e%e6%9b%b8%e3%82%92%e3%83%aa%e3%83%a2%e3%83%bc%e3%83%88%e3%83%87%e3%82%b9%e3%82%af%e3%83%88%e3%83%83%e3%83%97%e3%81%ae%e8%a8%bc/</link>
		<pubDate>Sat, 21 Apr 2018 16:53:50 +0000</pubDate>
		<dc:creator><![CDATA[jun]]></dc:creator>
				<category><![CDATA[コンピュータ]]></category>

		<guid isPermaLink="false">https://machijun.net/?p=1956</guid>
		<description><![CDATA[<p>はじめに リモートデスクトップで接続する際に、下記の警告に遭遇することがよくあります。 ほとんどの人が無視して接続していると思いますが、なりすましに気づけないなど好ましい状態ではないのでLet&#8217;s Encry [&#8230;]</p>
<p>The post <a href="https://ds.machijun.net/lets-encrypt%e3%81%a7%e4%bd%9c%e3%81%a3%e3%81%9f%e8%a8%bc%e6%98%8e%e6%9b%b8%e3%82%92%e3%83%aa%e3%83%a2%e3%83%bc%e3%83%88%e3%83%87%e3%82%b9%e3%82%af%e3%83%88%e3%83%83%e3%83%97%e3%81%ae%e8%a8%bc/">Let’s Encryptで作った証明書をリモートデスクトップの証明書に使う</a> first appeared on <a href="https://ds.machijun.net/">My Interests</a>.</p>]]></description>
				<content:encoded><![CDATA[<h2>はじめに</h2>
<p>リモートデスクトップで接続する際に、下記の警告に遭遇することがよくあります。<br />
<img class="alignnone size-full wp-image-1941 " src="https://imgds.machijun.net/wp-content/uploads/2018/04/21202618/img_5adb1fda3415d.png" alt="" srcset="https://imgds.machijun.net/wp-content/uploads/2018/04/21202618/img_5adb1fda3415d.png 461w, https://imgds.machijun.net/wp-content/uploads/2018/04/21202618/img_5adb1fda3415d-300x240.png 300w" sizes="(max-width: 461px) 100vw, 461px" /><br />
ほとんどの人が無視して接続していると思いますが、なりすましに気づけないなど好ましい状態ではないのでLet&#8217;s Encryptで作った証明書を使ってエラーを出なくしましょう。</p>
<p><span id="more-1956"></span><br />
<p class="ad-label">スポンサーリンク</p>
<div class="ad-innercontents">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- machijun.net-incontent -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-0727807216839004"
     data-ad-slot="9340959476"
     data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
</p>
<h2>証明書の入手</h2>
<p><a href="/lets-encrypt%e3%81%a7dns%e8%aa%8d%e8%a8%bc%e3%81%ab%e3%82%88%e3%82%8b%e3%83%af%e3%82%a4%e3%83%ab%e3%83%89%e3%82%ab%e3%83%bc%e3%83%89%e8%a8%bc%e6%98%8e%e6%9b%b8%e3%81%ae%e7%99%ba%e8%a1%8c/">こちら</a>を参考に入手してください。p12形式への変換も行い、そのファイルをWindowsへファイル転送しておいてください。<br />
＃上記ではワイルドカード証明書を作っていますが、通常の形式でも問題ありません。</p>
<h2>証明書のインポートと適用</h2>
<p>自動化も見据えてPowerShellでやってみます。</p>
<h3>PowerShellを管理者権限で起動</h3>
<p>スタートメニューでPowerShellを検索し、右クリック、「管理者として実行」で起動します。<br />
<img alt='' class='alignnone size-full wp-image-1947 ' src='https://imgds.machijun.net/wp-content/uploads/2018/04/22011822/img_5adb644e6295c.png' /></p>
<h3>証明書インポート</h3>
<p>以下のコマンドでインポートできます。<br />
&#8220;password&#8221;は証明書をp12形式にした際に指定したパスワードに置き換えてください。<br />
証明書ファイルのパスも実際のパスに置き換えてください。</p>
<pre class="brush: powershell; title: ; notranslate">
PS C:&gt; certutil -p password -importpfx .\certfile.p12
証明書 &quot;CN=*.example.com&quot; がストアに追加されました。

CertUtil: -importPFX コマンドは正常に完了しました。
</pre>
<h3>インポートした証明書をRDPで使うように設定する</h3>
<p>まずは、証明書のフィンガープリントを取得します。</p>
<pre class="brush: powershell; title: ; notranslate">
PS C:&gt; dir cert:\LocalMachine\My


    ディレクトリ: Microsoft.PowerShell.Security\Certificate::LocalMachine\My


Thumbprint                                Subject
----------                                -------
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX  CN=*.example.com
</pre>
<p>上記のXXXXXX&#8230;の部分がフィンガープリントです。<br />
複数あるものは有効期限（NotAfter）が最大のものを選ぶ必要があります。<br />
上記の出力ではわからないので下記コマンドを使用してください。</p>
<pre class="brush: powershell; highlight: [8,11,17,20]; title: ; notranslate">
PS C:&gt; dir cert:\LocalMachine\My


    ディレクトリ: Microsoft.PowerShell.Security\Certificate::LocalMachine\My | Format-List

Subject      : CN=*.example.com
Issuer       : CN=Let's Encrypt Authority X3, O=Let's Encrypt, C=US
Thumbprint   : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
FriendlyName :
NotBefore    : 2018/07/16 10:04:30
NotAfter     : 2018/10/14 10:04:30
Extensions   : {System.Security.Cryptography.Oid, System.Security.Cryptography.Oid, System.Security.Cryptography.Oid, S
               ystem.Security.Cryptography.Oid...}

Subject      : CN=*.example.com
Issuer       : CN=Let's Encrypt Authority X3, O=Let's Encrypt, C=US
Thumbprint   : YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
FriendlyName :
NotBefore    : 2018/04/21 17:20:13
NotAfter     : 2018/07/20 17:20:13
Extensions   : {System.Security.Cryptography.Oid, System.Security.Cryptography.Oid, System.Security.Cryptography.Oid, S
               ystem.Security.Cryptography.Oid...}
</pre>
<p>使う証明書のフィンガープリントがわかったら、下記のコマンドを実行します。<br />
XXXXX&#8230;部分を上記で取得したフィンガープリントに置き換えて実行してください。</p>
<pre class="brush: powershell; highlight: [16,27]; title: ; notranslate">
PS C:&gt; $cert = @{SSLCertificateSHA1Hash=&quot;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&quot;}
PS C:&gt; $path = (Get-WmiObject -class &quot;Win32_TSGeneralSetting&quot; -Namespace root\cimv2\terminalservices -Filter &quot;TerminalName='RDP-tcp'&quot;).__path
PS C:&gt; Set-WmiInstance -Path $path -argument $cert
__GENUS                                : 2
__CLASS                                : Win32_TSGeneralSetting
__SUPERCLASS                           : Win32_TerminalSetting
__DYNASTY                              : CIM_ManagedSystemElement
__RELPATH                              : Win32_TSGeneralSetting.TerminalName=&quot;RDP-Tcp&quot;
__PROPERTY_COUNT                       : 20
__DERIVATION                           : {Win32_TerminalSetting, CIM_Setting, CIM_ManagedSystemElement}
__SERVER                               : ServerName
__NAMESPACE                            : root\cimv2\terminalservices
__PATH                                 : \\ServerName\root\cimv2\terminalservices:Win32_TSGeneralSetting.TerminalN
                                         ame=&quot;RDP-Tcp&quot;
Caption                                :
CertificateName                        : *.example.com
Certificates                           : {0, 0, 0, 0...}
Comment                                :
Description                            :
InstallDate                            :
MinEncryptionLevel                     : 3
Name                                   :
PolicySourceMinEncryptionLevel         : 1
PolicySourceSecurityLayer              : 0
PolicySourceUserAuthenticationRequired : 0
SecurityLayer                          : 1
SSLCertificateSHA1Hash                 : XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
SSLCertificateSHA1HashType             : 3
Status                                 :
TerminalName                           : RDP-Tcp
TerminalProtocol                       : Microsoft RDP 6.1
Transport                              : tcp
UserAuthenticationRequired             : 0
WindowsAuthentication                  : 0
</pre>
<p>出力結果のCertificateNameが設定した証明書であり、SSLCertificateSHA1Hashが先ほど取得したものであることを確認して終了です。</p>
<h2>おまけ1）RDPでどの証明書が使われているか確認</h2>
<p>リモートデスクトップで対象のサーバに接続します。<br />
全画面表示にした際にでてくる、上部のバーの鍵マークをクリックして出てくるダイアログBOXの証明書の表示をクリックします。</p>
<p><img alt='' class='alignnone size-full wp-image-1949 ' src='https://imgds.machijun.net/wp-content/uploads/2018/04/22013254/img_5adb67b66cfef.png' /><br />
<img alt='' class='alignnone size-full wp-image-1950 ' src='https://imgds.machijun.net/wp-content/uploads/2018/04/22013313/img_5adb67c984517.png' /></p>
<h2>おまけ2）フィンガープリント確認と証明書適用を一緒にやる</h2>
<p>さらに自動化を見据えてこういう風に書けばコマンドの書き換え不要で流し込んで実行することができます。</p>
<pre class="brush: powershell; title: ; notranslate">
PS C:&gt; $cert = dir cert:\LocalMachine\My | 
 where{$_.Subject -match &quot;CN=\*.example.com$&quot; } |
 sort NotAfter -Des | Select -First 1 |
 Foreach{@{SSLCertificateSHA1Hash=$_.Thumbprint}}
PS C:&gt; $path = (Get-WmiObject `
-class &quot;Win32_TSGeneralSetting&quot; `
-Namespace root\cimv2\terminalservices  `
-Filter &quot;TerminalName='RDP-tcp'&quot;).__path 
PS C:&gt; Set-WmiInstance -Path $path -argument $cert
</pre>
<h2>参考リンク</h2>
<p>参考にさせていただきました。<br />
<a href="http://www.atmarkit.co.jp/ait/articles/1309/20/news036.html">http://www.atmarkit.co.jp/ait/articles/1309/20/news036.html</a></p><p>The post <a href="https://ds.machijun.net/lets-encrypt%e3%81%a7%e4%bd%9c%e3%81%a3%e3%81%9f%e8%a8%bc%e6%98%8e%e6%9b%b8%e3%82%92%e3%83%aa%e3%83%a2%e3%83%bc%e3%83%88%e3%83%87%e3%82%b9%e3%82%af%e3%83%88%e3%83%83%e3%83%97%e3%81%ae%e8%a8%bc/">Let’s Encryptで作った証明書をリモートデスクトップの証明書に使う</a> first appeared on <a href="https://ds.machijun.net/">My Interests</a>.</p>]]></content:encoded>
			</item>
		<item>
		<title>Let&#8217;s EncryptでDNS認証によるワイルドカード証明書の発行</title>
		<link>https://ds.machijun.net/lets-encrypt%e3%81%a7dns%e8%aa%8d%e8%a8%bc%e3%81%ab%e3%82%88%e3%82%8b%e3%83%af%e3%82%a4%e3%83%ab%e3%83%89%e3%82%ab%e3%83%bc%e3%83%89%e8%a8%bc%e6%98%8e%e6%9b%b8%e3%81%ae%e7%99%ba%e8%a1%8c/</link>
		<pubDate>Sat, 21 Apr 2018 11:15:51 +0000</pubDate>
		<dc:creator><![CDATA[jun]]></dc:creator>
				<category><![CDATA[コンピュータ]]></category>

		<guid isPermaLink="false">https://machijun.net/?p=1932</guid>
		<description><![CDATA[<p>はじめに Let&#8217;s EncryptでDNS認証を用いてワイルドカード証明書を発行します。 発行に使ったOSはCentOS7( CentOS Linux release 7.4.1708 (Core) )です [&#8230;]</p>
<p>The post <a href="https://ds.machijun.net/lets-encrypt%e3%81%a7dns%e8%aa%8d%e8%a8%bc%e3%81%ab%e3%82%88%e3%82%8b%e3%83%af%e3%82%a4%e3%83%ab%e3%83%89%e3%82%ab%e3%83%bc%e3%83%89%e8%a8%bc%e6%98%8e%e6%9b%b8%e3%81%ae%e7%99%ba%e8%a1%8c/">Let’s EncryptでDNS認証によるワイルドカード証明書の発行</a> first appeared on <a href="https://ds.machijun.net/">My Interests</a>.</p>]]></description>
				<content:encoded><![CDATA[<h2>はじめに</h2>
<p>Let&#8217;s EncryptでDNS認証を用いてワイルドカード証明書を発行します。<br />
発行に使ったOSはCentOS7( CentOS Linux release 7.4.1708 (Core) )です。</p>
<p><span id="more-1932"></span><br />
<p class="ad-label">スポンサーリンク</p>
<div class="ad-innercontents">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- machijun.net-incontent -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-0727807216839004"
     data-ad-slot="9340959476"
     data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>
</p>
<h2>certbotのインストール</h2>
<p><a href="https://letsencrypt.jp/usage/install-certbot.html#CentOS7" rel="noopener" target="_blank">公式</a>にあるとおり、yumコマンドで簡単にインストールできます。</p>
<pre class="brush: bash; title: ; notranslate">
[user@websv1 ~]$ sudo yum install epel-release
[user@websv1 ~]$ sudo yum install certbot
</pre>
<h2>証明書発行</h2>
<p>開始する前に、以下を準備してください。<br />
・メールアドレス（有効期限が近付いた際に通知が来ます）<br />
・DNSの管理アクセス権（当たり前ですが、DNSにレコード登録できないとこの手順は実行できません）</p>
<p>以下のコマンドを打ちます。<br />
メールアドレスとドメインは正しいものに書き換えて実行してください。</p>
<pre class="brush: bash; title: ; notranslate">
[user@websv1 ~]$ sudo certbot certonly \
 --manual \
 --server https://acme-v02.api.letsencrypt.org/directory \
 --email example@example.com \
 --agree-tos \
 --manual-public-ip-logging-ok \
 --preferred-challenges dns \
 --domain *.example.com
</pre>
<pre class="brush: bash; title: ; notranslate">
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org
Obtaining a new certificate
Performing the following challenges:
dns-01 challenge for example.com

-------------------------------------------------------------------------------
Please deploy a DNS TXT record under the name
_acme-challenge.example.com with the following value:

sQYXginymMXXXXXXXXXXXXXg8RFjTQ

Before continuing, verify the record is deployed.
-------------------------------------------------------------------------------
Press Enter to Continue
</pre>
<p>ここで、Enterを押す前に指定されたレコードをDNSに登録します。<br />
この例では[_acme-challenge]というTXTレコードを[example.com]に作ってください。<br />
レコードに指定された「sQYXginy&#8230;.」という値を登録します。</p>
<p>反映に時間がかかるかもしれないので、少し待ってからEnterを押してください。</p>
<pre class="brush: plain; title: ; notranslate">
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/example.com/privkey.pem
   Your cert will expire on 2018-07-20. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   &quot;certbot renew&quot;
 - 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
</pre>
<p>/etc/letsencrypt/live/example.com/ に作成された証明書と秘密鍵があります。</p>
<h2>おまけ）p12形式への変換</h2>
<p>WindowsやIISで使うために、p12形式に変更します。<br />
・opensslが入っていなければyumでインストールしてください。<br />
・/etc/letsencrypt/live/example.com/　への読み書き権限のあるユーザで作業してください。</p>
<pre class="brush: bash; title: ; notranslate">
[user@websv1 ~]$ cd /etc/letsencrypt/live/example.com/
[user@websv1 example.com] openssl pkcs12 -export -out certfile.p12 -in cert.pem -inkey privkey.pem
Enter Export Password: (任意のパスワードを入力)
Verifying - Enter Export Password: (再度上記と同じパスワードを入力)
</pre>
<p>これで、/etc/letsencrypt/live/example.com/にcertfile.p12ができました。</p><p>The post <a href="https://ds.machijun.net/lets-encrypt%e3%81%a7dns%e8%aa%8d%e8%a8%bc%e3%81%ab%e3%82%88%e3%82%8b%e3%83%af%e3%82%a4%e3%83%ab%e3%83%89%e3%82%ab%e3%83%bc%e3%83%89%e8%a8%bc%e6%98%8e%e6%9b%b8%e3%81%ae%e7%99%ba%e8%a1%8c/">Let’s EncryptでDNS認証によるワイルドカード証明書の発行</a> first appeared on <a href="https://ds.machijun.net/">My Interests</a>.</p>]]></content:encoded>
			</item>
	</channel>
</rss>
