LoginSignup
5
1
AWS Secrets Managerに登録された秘密鍵から公開鍵を作る方法
$ ssh-keygen -y -f <(aws secretsmanager get-secret-value --secret-id {secret名} --query 'SecretBinary' --output text --profile {profile名} | base64 --decode) > {公開鍵}.pub

はじめに

AWS Secrets Managerにバイナリで登録された秘密鍵のペアになる公開鍵を作りたい。
なんとなくローカルに秘密鍵を出力してそこから公開鍵をつくらず、ローカルに秘密鍵出力するのも嫌だしワンライナーでやってみたかった。

ご利用および鍵の取り扱いは自己責任でお願いいたします。

コマンドの説明

  • 環境
    • Windows 11 Pro
    • aws-cli/2.13.25
    • base64 (GNU coreutils) 8.32

AWS Secrets Managerにバイナリで登録された秘密鍵を取得する

バイナリで登録されたものは画面からは取得できないのでCLIで取得する。
参考 : GetSecretValue - AWS Secrets Manager

aws secretsmanager get-secret-value --secret-id {secret名} --query 'SecretBinary' --output text --profile {profile名}

Base64でバイナリをデコードする

# 「--decode」は「-d」でもOK
base64 --decode

公開鍵を作る

# ファイルを指定して(-f)OpenSSH形式で秘密鍵から公開鍵を作る(-y)
ssh-keygen -y -f... > {公開鍵}.pub

全部をつなげる

「|(パイプ)」でつながず「<」を使う、というところにつまずいた。
「<」がなんという名前かがわからず、ググれず「リダイレクトの逆」と検索したりした。

$ ssh-keygen -y -f <(aws secretsmanager get-secret-value --secret-id {secret名} --query 'SecretBinary' --output text --profile {profile名} | base64 --decode) > {公開鍵}.pub
5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1