6

I have a script that I run with geth attach, and then I use:

primary = eth.accounts[0];
personal.unlockAccount(primary, "password");

like I saw in the example script.

Doing this in geth usually takes about one or two seconds. I learned there was another way to unlock accounts. I was wondering if it was faster to unlock directly with geth --unlock "0xaddress" --password "password" attach. What does it do differently ?

How can I know if it unlocked successfully ? If I use a random address or password instead of the correct ones, attach still opens correctly.

EDIT: I found in the answer of a duplicate question that you can't use --unlock with attach, which wasn't in the original answer (or at least not clearly).

Geth attach "opens correctly" because it ignores those flags. You can run geth --unlock "0xaddress" --password "password" attach or geth --password --testnet --testnet attach and it will open like geth attach (flag order seems to be important sometimes though, you can't use password after testnet or it ignores attach).

3

--unlock also takes a second, no benefit here. On the other hand, not showing your password on the command line is a net benefit. Yes, make it --password password_file.txt instead of plain password in the command.

If it failed to decrypt, then Geth will exit with error code 1:

$ geth --unlock "0" --password password_file.txt
...
Fatal: Failed to unlock account 0 (could not decrypt key with given passphrase)
$ echo $?
1
  • Thanks. Does --password always expect a file path ? If I have my password in a variable, could --password $password work ? I can't get it to work. My primary account is unlocked automatically for some reason, and I can't unlock my second with --unlock – Teleporting Goat Jan 17 '17 at 12:48
  • just an information about --password when you use it with plain text password keep in mind your password will be shown in the log. – Badr Bellaj Jan 17 '17 at 13:30
  • @Xavier what do you mean by net benefit? – Badr Bellaj Jan 17 '17 at 13:30
  • @BadrBellaj Can I even use it with plain password ? How does geth know ? – Teleporting Goat Jan 17 '17 at 13:32
  • 1
    I never tried passing the password plainly in the command line. But, if it were possible, having a password just accessible in the history of my shell is a liability. Not having it in the history is a net benefit. – Xavier Leprêtre B9lab Jan 17 '17 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.