🔒
ArchLinuxで1password-cliをインストールする
実行環境
- Windows11 WSL2(ArchLinux)
公式ドキュメント
Get started with 1Password CLI
インストール
AURヘルパー yay でインストールできます。
AURヘルパーが未導入の場合は以下のようにインストールします。
(cd /tmp && git clone https://aur.archlinux.org/yay.git && cd yay && makepkg -si --noconfirm)
yay が利用可能になったら、次のコマンドで1Password CLIをインストールします。
yay -S 1password-cli
インストール後、コマンドが実行できるか確認します。
op --version
アカウント設定
アカウントの初期設定を行います。
op account add --account myaccount
myaccount は任意の名前で問題ありません。
未指定の場合はサインインアドレスがそのまま設定されます。
コマンド実行後、以下の順に入力を求められます。
Enter your sign-in address (example.1password.com):
Enter the email address for your account on example.1password.com:
Enter the Secret Key for your.email@example.com on example.1password.com:
Enter the password for your.email@example.com at example.1password.com:
Enter your six-digit authentication code:
- サインインアドレス(例: example.1password.com)
- メールアドレス(例: your.email@example.com)
- Secret Key(1Passwordアカウント作成時に発行されたキー)
- パスワード(1Passwordアカウントのログインパスワード)
- 2段階認証コード(Authenticator等の認証アプリで確認)
認証
以下のコマンドでサインインします。
セッションが切れるたびに実行が必要で、セッションは30分で切れるため、基本的に毎回認証を行います。
また、アカウントが一つだけの場合は --account myaccount を省略できます。
eval $(op signin --account myaccount)
セッション状況の確認は op whoami で出来るため、『セッションが切れていたらサインインする』は以下のように実行します。
※ ただ私の環境(zsh+starship)ではうまく動かず、素のプロンプト( zsh -f )だと期待通り動きました。
op whoami &>/dev/null || eval $(op signin --account myaccount)
まとめ
これで1Passwordに任せられる範囲が広がりました。
スクリプト内でTOKENやKEYを参照したり、.envファイルにパスワードを直接打つ必要がなくなるのは良いですね。
Discussion