{"record":{"id":"d89bf2f53a623c89","repo":"hashicorp/vagrant","slug":"vagrant-failed-to-copy-the-default-insecure-privat","errorCode":null,"errorMessage":"Vagrant failed to copy the default insecure private key into your\nhome directory. This is usually caused by a permissions error.\nPlease make sure the permissions of the source is readable and\nthe destination is writable.\n\nSource: %{source}\nDestination: %{destination}","messagePattern":"Vagrant failed to copy the default insecure private key into your\nhome directory\\. This is usually caused by a permissions error\\.\nPlease make sure the permissions of the source is readable and\nthe destination is writable\\.\n\nSource: %(.+?)\nDestination: %(.+?)","errorType":"exception","errorClass":"Vagrant::Errors::CopyPrivateKeyFailed","httpStatus":null,"severity":"error","filePath":"lib/vagrant/environment.rb","lineNumber":1094,"sourceCode":"    # `default_private_keys_directory` contains the list of valid private\n    # keys supported by Vagrant.\n    #\n    # NOTE: The keys are copied because `ssh` requires that the key is chmod\n    # 0600, but if Vagrant is installed as a separate user, then the\n    # effective uid won't be able to read the key. So the key is copied\n    # to the home directory and chmod 0600.\n    def copy_insecure_private_keys\n      # First setup the deprecated single key path\n      if !@default_private_key_path.exist?\n        @logger.info(\"Copying private key to home directory\")\n\n        source      = File.expand_path(\"keys/vagrant\", Vagrant.source_root)\n        destination = @default_private_key_path\n\n        begin\n          FileUtils.cp(source, destination)\n        rescue Errno::EACCES\n          raise Errors::CopyPrivateKeyFailed,\n            source: source,\n            destination: destination\n        end\n      end\n\n      if !Util::Platform.windows?\n        # On Windows, permissions don't matter as much, so don't worry\n        # about doing chmod.\n        if Util::FileMode.from_octal(@default_private_key_path.stat.mode) != \"600\"\n          @logger.info(\"Changing permissions on private key to 0600\")\n          @default_private_key_path.chmod(0600)\n        end\n      end\n\n      # Now setup the key directory\n      Dir.glob(File.expand_path(\"keys/vagrant.key.*\", Vagrant.source_root)).each do |source|\n        destination = default_private_keys_directory.join(File.basename(source))\n        default_private_key_paths << destination","sourceCodeStart":1076,"sourceCodeEnd":1112,"githubUrl":"https://github.com/hashicorp/vagrant/blob/35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5/lib/vagrant/environment.rb#L1076-L1112","documentation":"Raised as Vagrant::Errors::CopyPrivateKeyFailed from copy_insecure_private_keys (lib/vagrant/environment.rb:1094) when FileUtils.cp of the bundled source keys/vagrant file into the default insecure private key path under the Vagrant home (~/.vagrant.d/...) raises Errno::EACCES — the destination (or source) is not writable/readable due to permissions.","triggerScenarios":"First run on a machine where the home directory's key location is not writable by the current user — root-owned ~/.vagrant.d after earlier sudo use, hardened read-only home, or a VAGRANT_HOME path without write permission — so copying the default key fails during environment setup.","commonSituations":" sudo vagrant used once, then normal user; home directories on locked-down corporate images; running as a service account whose $HOME is not writable.","solutions":["Fix ownership of the destination tree: `sudo chown -R $(id -u):$(id -g) ~/.vagrant.d` and ensure it is writable (chmod u+w)","Verify the source is readable (it ships inside the Vagrant install; a broken install re-install fixes it)","If $HOME cannot be made writable, point Vagrant elsewhere: `export VAGRANT_HOME=/writable/path/vagrant.d`","Avoid running vagrant as root/mismatched users in the same home"],"exampleFix":"# before\n$ sudo chown -R root:root ~/.vagrant.d   # (or created by earlier sudo run)\n$ vagrant up   # CopyPrivateKeyFailed\n\n# after\n$ sudo chown -R $(id -u):$(id -g) ~/.vagrant.d\n$ vagrant up","handlingStrategy":"validation","validationCode":"home = ENV[\"VAGRANT_HOME\"] || File.expand_path(\"~/.vagrant.d\")\nraise ArgumentError, \"#{home} not writable — key copy will fail\" unless File.writable?(home)\n# source ships with the install; destination is home/insecure_private_key","typeGuard":null,"tryCatchPattern":"begin\n  env = Vagrant::Environment.new\nrescue Vagrant::Errors::CopyPrivateKeyFailed => e\n  abort \"Cannot copy key #{e.extra_data[:source]} -> #{e.extra_data[:destination]}: fix permissions\"\nend","preventionTips":["Keep ~/.vagrant.d owned and writable by the vagrant user","Avoid sudo vagrant; if unavoidable, chown -R the home afterwards","Redirect VAGRANT_HOME on hosts with read-only $HOME"],"tags":["vagrant","ssh-key","permissions","home-directory","eacces"],"backgroundTag":"permission-denied","analyzedSha":"35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5","analyzedAt":"2026-08-21T13:34:32.514Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}