ipfs/kubo · error

cannot export key with name 'self'

Error message

cannot export key with name 'self'

What it means

Reserved-name guard in `ipfs key export`: the requested export name is 'self', the node's own private identity key. Exporting it would leak the node's primary identity private key to a file, so the command hard-refuses the operation before reading the keystore.

Source

Thrown at core/commands/keystore.go:195

elsewhere. For example, using openssl to get a PEM with public key:

  $ ipfs key export testkey --format=pem-pkcs8-cleartext -o privkey.pem
  $ openssl pkey -in privkey.pem -pubout > pubkey.pem
`,
	},
	Arguments: []cmds.Argument{
		cmds.StringArg("name", true, false, "name of key to export").EnableStdin(),
	},
	Options: []cmds.Option{
		cmds.StringOption(outputOptionName, "o", "The path where the output should be stored."),
		cmds.StringOption(keyFormatOptionName, "f", "The format of the exported private key, libp2p-protobuf-cleartext or pem-pkcs8-cleartext.").WithDefault(keyFormatLibp2pCleartextOption),
	},
	NoRemote: true,
	Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
		name := req.Arguments[0]

		if name == "self" {
			return fmt.Errorf("cannot export key with name 'self'")
		}

		cfgRoot, err := cmdenv.GetConfigRoot(env)
		if err != nil {
			return err
		}

		// Check repo version, and error out if not matching
		ver, err := migrations.RepoVersion(cfgRoot)
		if err != nil {
			return err
		}
		if ver != fsrepo.RepoVersion {
			return fmt.Errorf("key export expects repo version (%d) but found (%d)", fsrepo.RepoVersion, ver)
		}

		// Export is read-only: safe to read it without acquiring repo lock
		// (this makes export work when ipfs daemon is already running)

View on GitHub (pinned to 329838acdf)

Solutions

  1. Export only user-created keys by name, e.g. ipfs key export mykey
  2. Back up the full repo (including the identity key) instead if you truly need the self key
  3. Generate a separate key with ipfs key gen and export that one
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at core/commands/keystore.go:195 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of ipfs/kubo@329838acdf (2026-09-03). Data as JSON: /api/errors/d7576684309e79d2. Report an issue: GitHub.