èæ¯
æ¡ä»¶ã«ãã£ã¦ã¯ãWindows ãè¸ã¿å°ã¨ãã¦ä½æããLinux ã¸æ¥ç¶ãè¡ããã¨ãã£ãã±ã¼ã¹ãããã¨æãã¾ãã
ãã®ã¨ããTeraterm ã使ã£ã¦ SSH æ¥ç¶ãè¡ããã¨ãå¤ãã®ã§ãpem ãã¡ã¤ã«ã Windows ã¸éã¶ã¨ãããã¨ãããã§ãããã
RDP ã¸ã³ããã許ããã¦ããã°ç¹ã«åé¡ã¯ãªãã®ã§ãããå ´åã«ãã£ã¦ã¯ pem ãã¡ã¤ã«ããã¦ã³ãã¼ããã¦æã£ã¦ããå¿ è¦ããããã¨æãã¾ãã
ä¾ãã° AWS ã§ããã¨ãéå網ãæ§æããã¨ãªã£ãå ´åãVPC ã¨ã³ããã¤ã³ããç¨æãã¦ã·ã¼ã¯ã¬ããããã¼ã¸ã£ã¼ã«éµãæ ¼ç´ãã¦å¼ã£å¼µã£ã¦ããã®ãå®çªã§ãããã ï¼AWS CDK ãªããã§ã Secret Manager ã«ç§å¯éµãåºããããã¾ããï¼
ãã®å ´åãpowershell ä¸ãã AWS CLI ãå©ãã¦ããã¡ã¤ã«ãæã£ã¦ãããã¨ã«ãªãã¾ããã
èµ·ãããã¡ãªåé¡
Powershell ä¸ã§ AWS CLI ãå©ç¨ãããã以ä¸ã®ããã«ãªãã¬ã¯ããè¡ã£ã¦ pem ãã¡ã¤ã«ã¨ãã¦æ¸ãè¾¼ã¿ãè¡ããããªãã¨æãã¾ãã
aws secretsmanager get-secret-value --secret-id <ARN> --query 'SecretString' --output text > hoge.pem
ãã®ãã¡ã¤ã«ã使ã£ã¦ãTeraterm ããæ¥ç¶ãè¡ããã¨ããã¨ä»¥ä¸ã®ãããªã¨ã©ã¼ãçºçãã¾ãã
read error SSH2 private key file error:09FFF06C:PEM routines:CRYPTO_internal:no start line
Web ä¸ãæ¤ç´¢ãã¦ã¿ãã¨ãç§å¯éµã®ãã©ã¼ããããééã£ã¦ãããæ¹è¡å¨ãã調æ´ããã°ãããï¼ã¿ãããªãã¨ãæ¸ããã¦ãã¾ãããã©ãã ãæ¹è¡å¨ãã調æ´ãã¦ããã¾ãããã¾ããã
ããã¯ãBOM ã¨ãããã¼ã¿ã Powershell ã®ãªãã¤ã¬ã¯ãã«ãã£ã¦ä»å ããã¦ããããã§ãã
çµè«
Powershell ä¸ã§ãªãã¤ã¬ã¯ããè¡ãã¨ãå®ã¯ BOM ï¼Byte Order Markï¼ã¨ãããã®ãæ¿å ¥ããã¾ãã ãªã®ã§ããªãã¤ã¬ã¯ããè¡ããã³ããããããããªãã¤ã¬ã¯ããããã¡ã¤ã«ãã BOM ãåãé¤ãå¿ è¦ãããã¾ãã
BOM ãåãé¤ãããå ´åãã¡ã¢å¸³ããä¿åå½¢å¼ã¨ã㦠BOM ãªãã§ã®ä¿åãå¯è½ã§ãã
ããã°ã©ã ã ãã§ããåãããå ´åã¯ãèªåã§ãããããªãããã§ãããã¸ãã ãã¤ããªã¨ãã¦ãã¡ã¤ã«ãèªã¿è¾¼ãã§ã対象㮠BOM ãåé¤ããã°ãããããã§ãã
ã¡ãªã¿ã«ãã®ãªãã«ã¨ã³ãã£ã¢ã³ UTF-16 㯠Powershell ã®ä»æ§ã§ãã£ã¡ãã¨ããã¥ã¡ã³ãã«æ¸ãã¦ããã¾ãã ï¼ããã¾ããã®ä»æ§ãç¥ããã«ãã®ããã¥ã¡ã³ãã«ãã©ãçããã¨ã¯å°åºæããªããã©ï¼
In general, Windows PowerShell uses the Unicode UTF-16LE encoding by default. However, the default encoding used by cmdlets in Windows PowerShell is not consistent.
Note Using any Unicode encoding, except UTF7, always creates a BOM.
çµè«ã¨ãã¦ã¯ããã§çµããã§ãããBOM ã¨ã¯ä½ããã£ãã確èªãã¾ãããã
BOM ã¨ã¯
BOMï¼Byte Order Markï¼ã¯ãããã¹ããã¡ã¤ã«ã®å é ã«ä»å ãããç¹æ®ãªæååã§ãåºæ¬ã¯ä»¥ä¸ 2 ã¤ã®ç®çã§æ¿å ¥ããã¾ãã
ã¨ã³ã³ã¼ãã£ã³ã°ï¼å¯¾è±¡ã®ãã¡ã¤ã«ã®æåã¨ã³ã³ã¼ãã£ã³ã°ãæå®ãã¾ãï¼UTF-8,16,32 ãªã©ï¼
ãã¤ããªã¼ãã¼ã®æå®ï¼UTF-16 ã UTF-32 ã®ããã«è¤æ°ãã¤ãã使ç¨ããã±ã¼ã¹ã§ã¯ããã¤ããã©ã®ãããªé åºã§æ ¼ç´ãããã示ãã¾ã
æ¿å ¥ãããå¤ã¯ä»¥ä¸ã®ããã«æ±ºã¾ã£ã¦ãã¾ãã - UTF-8: EF BB BF - UTF-16 (Big Endian): FE FF - UTF-16 (Little Endian): FF FE - UTF-32 (Big Endian): 00 00 FE FF - UTF-32 (Little Endian): FF FE 00 00
ãã¤ããªã¼ãã¼ã£ã¦è¨ããã¦ãæåã¯ãªããªããã³ã¨ããªãã®ã§ãã¡ãã確èªãã¾ãããã
ãªãã«ã¨ã³ãã£ã¢ã³ã¨ããã°ã¨ã³ãã£ã¢ã³
ãã¤ããªã¼ãã¼ã¨ã¯ããã®ååã®éãããã¤ããã©ã®ããã«ä¸¦ã¹ããï¼ã¨ããé çªã§ãã ããã¯è¤æ°ã®ãã¤ãã1ã¤ã®åä½ã¨ãã¦èªèãã¦æ±ãã¨ã³ã³ã¼ãã£ã³ã°ã®å ´åããã®è¤æ°ã®ãã¤ããã©ã®ããã«ä¸¦ã¹ãã®ãï¼ã«ãã£ã¦å ¨ãæå³ãç°ãªã£ã¦ãã¾ãã ãã¤ããªã¼ãã¼ã«ã¯ããªãã«ã¨ã³ãã£ã¢ã³ã¨ããã°ã¨ã³ãã£ã¢ã³ã®2種é¡ãããã¾ãã
ã¾ã ãä½ã¨ãªãæå³ãåããã¥ããã®ã§ããå°ã詳ããè¦ã¦ã¿ã¾ãã
ã¾ã大åæã¨ãã¦ãã¡ã¢ãªããããã¯ä¸ã«ã¯åºæ¬çã« 1 byte åä½ã§ãã¼ã¿ãæ ¼ç´ããã¦ãã¾ãã
UTF-16 㯠2 byte ãåºæ¬åä½ãUTF-32 㯠4 byte ãåºæ¬åä½ã«ãªãã¾ãã ä¾ãã°ãUTF-16 ã«ããã¦è±èªã®ãzãã¯ãU+007A ã§ãã00ãã¨ã7Aãã®2ã¤ã® byte ã§è¡¨ããã¾ãã
ãã ããã® 2byte ãã©ã®ããã«ã¡ã¢ãªãªã©ã§æ ¼ç´ãããã®ããä¸ä½ãã¤ãããæ ¼ç´ããããä¸ä½ãã¤ãããæ ¼ç´ãããã«ãã£ã¦ã2ãã¿ã¼ã³ãããããããã¤ããªã¼ãã¼ã¨å¼ã°ãããã®ã§ãã
ç¾ä»£ã§ã¯åºæ¬çã«ãªãã«ã¨ã³ãã£ã¢ã³ã主æµãªã®ã§ãããããªãã«ã¨ã³ãã£ã¢ã³ã§è§£éããã¦ããã¨ãã¾ãããã ããã§ãæ¬æ¥ãªãã«ã¨ã³ãã£ã¢ã³ã§è§£éããªããã°ãªããªããã®ãã誤ã£ã¦ããã°ã¨ã³ãã£ã¢ã³ã§è§£éãã¦ãã¾ãã¨ã007A ã®éã® 7A00 ã¨ãã¦è§£éããã¦ãã¾ãã¾ãã
7A00 ï¼U+7A00ï¼ã¯æ¼¢åã®ãç¨ãã«ãããã¾ããããããããæååããçºçãã¾ãã
å®éã« Windows ç°å¢ã§è©¦ãã¦ã¿ãã¨ã以ä¸ã®ãããªçµæãå¾ããã¾ãã æåã® 255, 254 㯠0xFF, 0xFE ã® UTF-16 ã®ãªãã«ã¨ã³ãã£ã¢ã³ã® BOM ã§ãã 次ã«ç¶ã 122, 0 㯠0x7A, 0x00 ã§ãããããï½ãU+7A00 ããã£ã¡ããªãã«ã¨ã³ãã£ã¢ã³ã§æ ¼ç´ããã¦ãã¾ããã 0, 13, 0, 10 㯠Windows ã®æ¹è¡ã§ãã CRLFï¼\r\nï¼ã§ããUTF-16 㯠2byte åºå®é·ãªã®ã§ãæ¹è¡ã 2byte 使ããã¦ãã¾ãã
PS C:\Users\Administrator> echo z > .\z.txt PS C:\Users\Administrator> get-content .\z.txt -Encoding Byte 255 254 122 0 13 0 10 0
ã§ã¯ããï½ãã®é¨åã®ãã¤ãé ãéã«ãã¦ã¿ã¾ãã ããã§ãæ¬æ¥ããã°ã¨ã³ãã£ã¢ã³ã§ãï½ãã¨è¡¨è¨ãããã£ããã®ãããªãã«ã¨ã³ãã£ã¢ã³ã§è§£éãããã¨ã«ãªãã¾ãã
PS C:\Users\Administrator> $byteArray = [byte[]](255, 254, 0, 122, 13, 0, 10, 0) PS C:\Users\Administrator> [System.IO.File]::WriteAllBytes(".\reverse-z.txt", $byteArray) PS C:\Users\Administrator> get-content .\reverse-z.txt ç¨
æ¼¢åã®ãç¨ãã表示ããã¾ããã ãã㯠U+7A00 ã®æåã§ãããã綺éºã«æååããèµ·ãããã¨ãã§ãã¾ããã BOM ã大äºãªå½¹å²ãæããã¦ããã£ã¦ã®ããªãã¨ãªãç解ã§ãã¾ããã
ã¡ãªã¿ã« Linux ã§ã¯ãåºæ¬çã« UTF-8 ãä¸è¬çã«å©ç¨ããããããç¹ã« BOM ãã¤ããå¿ è¦ã¨ããã¾ããã ï¼ããã pem ãã¡ã¤ã«ã®ä»¶ã®ããã«ãä½ãã¨åé¡ã«ãªããã¨ãå¤ãã§ãï¼
UTF-8 ã¯å¯å¤é·ã®æåã¨ã³ã³ã¼ãã£ã³ã°ã§ããã1æåã表ãéã«ãã®æåãä½ byte ã§è¡¨ãããã®ãã示ãããã®å¶å¾¡ bit ãå©ç¨ãã¾ãã ãã®ãããåã«ã¤ãã¦ããå¶å¾¡ bit ãã¾ãèªã¾ãªããã°ãªããªãã®ã§ãåãã 1byte åä½ã§å¦çãã¦ããã»ãããã¾ããã ã¤ã¾ãããã¤ããªã¼ãã¼ã¨ããæ¦å¿µããªãã®ã§ãBOM ãªã©ãã¤ããå¿ è¦ããªãããã§ãã ï¼Windows ã«ã¯ UTF-8 ã§ãäºææ§ã®ãã BOM ãã¤ãããã¨ãã§ãã¾ãï¼
ä½è«1ï¼Powershell ã BOM ãã¤ããçç±
ãã¡ãã¯ä»¥ä¸ã®ããã°ã詳ããã£ãã§ãã
Windows ã¯å é¨çã«ã¯ UTF-16 ã§åºæ¬çã«å¦çãè¡ãã®ã§ãBOM ä»ã UTF-16 ãå©ç¨ãããã¨ãå¤ãã£ãã®ãèæ¯ã®ããã§ãã UTF-16 㯠2byte åºå®é·ãªã®ã§ãBOM ãå¿ è¦ã«ãªãããã§ããã
PowerShellã¯ã¯ãã¹ãã©ãããã©ã¼ã ãªã¢ããªã±ã¼ã·ã§ã³ã¨ãªã£ã¦ãã¾ãããå ã ã¯Windowsã®.NET Frameworkä¸ã§åä½ããã¢ããªã±ã¼ã·ã§ã³ã§ããã
ãã®ããPowerShellã§åãæ±ããæåã³ã¼ãã¯.NET Frameworkããã³Windowsã®å½±é¿ã大ããåãã¦ãã¾ãã ãªãã¤ã¬ã¯ãæ¼ç®åããã¡ã¤ã«æä½ã«é¢ããã³ãã³ãã¬ããã®æ¢å®ã®ã¨ã³ã³ã¼ãã£ã³ã°ãBOMä»ãUTF-16ã§ãããã¨ãUTF-8ãBOMä»ããªã®ã¯ãåºæ¬çã«ã¯.NET Frameworkã«ãããã¨ã³ã³ã¼ãã£ã³ã°ãããã§ããå½±é¿ã§ãã
ä½è«2ï¼ãªãã«ã¨ã³ãã£ã¢ã³ãç¾ä»£ã§ã¯ä¸»æµãªçç±
ãªãã«ã¨ã³ãã£ã¢ã³ã主æµãªçç±ã¯ä»¥ä¸ã®2ã¤ããã£ã½ãã§ãã
è¨ç®ãå¹çç çç®ãèããã¨ããããããã§ãããåºæ¬çã«è¨ç®ã¯å°ããæ¡ããè¡ã£ã¦ãããç¹°ãä¸ããèæ ®ããã®ãæ®éã§ãã ãã®ããããªãã«ã¨ã³ãã£ã¢ã³ã ã¨åããå¦çãè¡ããã®ã§ãå¹ççã«è¨ç®ãè¡ãã¾ãã
x86 ã¢ã¼ããã¯ãã£ã§ã®æ¡ç¨ ãã¡ãã¯æ´å²çãªèæ¯ã§ãããä¸çä¸ã§å¹ åºã使ããã¦ãã Intel ã® x86 ã§æ¡ç¨ããããã¨ã大ããªçç±ã®ä¸ã¤ã®ããã§ãã