Manage your EOS account keys with Docker, cleos and keosd

in #eos6 years ago (edited)

Overview

<p dir="auto">How to change/manage your EOS keys (owner/active) from the command line using the official Docker image from EOSIO. <p dir="auto">This is a very techincal post, if you prefer a UI you could check out the greymass wallet. <p dir="auto">You'll need your private key from your existing EOS account to make these updates. <h2>TL;DR <ol> <li>Run <code>keosd with Docker <li>Set a <code>cleos alias to execute commands inside the docker container using your local <code>keosd instance <li>Run a bunch of command line operations <h2>Process <p dir="auto">This post was written at the time of EOS version 1.2.2. <p dir="auto">The following steps are done using bash or zsh using Linux, should also run on OSX and Windows with the appropriate software installed (Docker, bash/zsh). <p dir="auto">Start a docker container using the offical eos-dev image from eosio: <p dir="auto"><code>docker run --rm --name keosd -it -v ~/eosio-wallet:/tmp/eosio-wallet eosio/eos-dev keosd --wallet-dir /tmp/eosio-wallet <p dir="auto">Note: You don't need to mount a volume if you don't want to keep your wallet around. <p dir="auto">Create an alias to run the cleas commands inside the docker container: <p dir="auto"><code>alias cleos='docker exec -it keosd /opt/eosio/bin/cleos -u http://eos.greymass.com --wallet-url http://127.0.0.1:8888' <p dir="auto">Set an environment variable with your EOS account name so we can reuse it easily: <p dir="auto"><code>export ACCOUNT_NAME=************* <p dir="auto">Check it's all working, get your account details: <p dir="auto"><code>cleos get account $ACCOUNT_NAME <p dir="auto">List wallets (we have none yet): <p dir="auto"><code>cleos wallet list <p dir="auto">Create a wallet: <p dir="auto"><code>cleos wallet create -n $ACCOUNT_NAME --to-console <p dir="auto">Save the password for the wallet, we'll be using it again. <p dir="auto">Import the existing <strong>owner key to the wallet. <p dir="auto"><strong>Note: there's a space at the start of commands with our priviate keys so they don't save to history: <p dir="auto"><code>cleos wallet import -n $ACCOUNT_NAME --private-key ************ <p dir="auto">List keys: <p dir="auto"><code>cleos wallet keys <p dir="auto">Create a new <strong>owner key and save it with your encryption software: <p dir="auto"><code>cleos create key --to-console <p dir="auto">Create a new <strong>active key and save it with your encryption software: <p dir="auto"><code>cleos create key --to-console <p dir="auto">Set the new <strong>active key, replace <code>EOS******* with your <strong>public active key <p dir="auto"><code>cleos set account permission $ACCOUNT_NAME active EOS******* owner -p $ACCOUNT_NAME@owner <p dir="auto">Set the new <strong>owner key, replace <code>EOS******* with your <strong>public owner key <p dir="auto"><code>cleos set account permission $ACCOUNT_NAME owner EOS******* -p $ACCOUNT_NAME@owner <p dir="auto">List keys: <p dir="auto"><code>cleos wallet keys <p dir="auto">The current local wallet key is now change, remove it: <p dir="auto"><code>cleos wallet remove_key -n $ACCOUNT_NAME EOS******* <p dir="auto">We want to vote, or re-vote to avoid vote decay. Add the private key of your new <strong>active key to your wallet: <p dir="auto"><code>cleos wallet import -n $ACCOUNT_NAME --private-key PRV************ACITVE_KEY <p dir="auto">Vote. In this example we use a proxy: <p dir="auto"><code>cleos system voteproducer proxy $ACCOUNT_NAME investingwad <p dir="auto">Optional: clean up / reset. <p dir="auto">List keys: <p dir="auto"><code>cleos wallet keys <p dir="auto"><code>cleos wallet remove_key -n $ACCOUNT_NAME EOS******* <h2>References <p dir="auto">Thanks to <a href="https://medium.com/@cc32d9/changing-the-private-key-for-an-eos-account-58a79dc385cd" target="_blank" rel="nofollow noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">cc32d9 for the kickstart.