2

I am trying to change my neo4j password through the following command line operation, following Brent Barbata's answer on this link

curl -H "Content-Type: application/json" -XPOST -d '{"password":"new_password"}' -u neo4j:neo4j http://localhost:7474/user/neo4j/password

But I am getting the following error

{
  "errors" : [ {
    "code" : "Neo.ClientError.Security.Unauthorized",
    "message" : "Invalid username or password."
  } ]

I tried this alternate way following the ideas from this question

curl -H "Content-Type: application/json"\ -H "Authorization: Basic `echo -n 'USERNAME:OLDPASSWORD | base64`"\ -X POST -d '{"password":"NEWPASSWORD"}'\ -I http://localhost:7474/user/neo4j/password

And got the following error

curl: (6) Could not resolve host: Authorization
curl: (6) Could not resolve host: POST
{
  "errors" : [ {
    "code" : "Neo.ClientError.Security.Unauthorized",
    "message" : "No authentication header supplied."
  } ]

Whats wrong in these methods and what is the way to change password? I do not want to use :server change-password on browser. I am running neo4j 3.3.5 on Ubuntu 16.04

harshvardhan
  • 765
  • 13
  • 32

2 Answers2

2

If it's to initially set the password (i.e. before the first start of the server):

bin/neo4j-admin set-initial-password MyNewPassWord

If it's to change your password, just connect to the cypher-shell with your login/password and then execute this query:

CALL dbms.security.changePassword('MyNewPassWord')
Logan
  • 10,649
  • 13
  • 41
  • 54
logisima
  • 7,340
  • 1
  • 18
  • 31
1

I tried out your examples on my own instance of Neo4j and was met with the same errors. I found this slightly different command from this source and this works for me. No error messages are returned and it instantly changes your password.

curl -H "Content-Type: application/json" -H "Authorization: Basic `echo -n 'USERNAME:OLDPASSWORD' | base64`" -X POST -d '{"password":"NEWPASSWORD"}' -I http://localhost:7474/user/neo4j/password

It looks almost exactly the same as the second curl command in your question - my guess is, with the line continuation characters and the general messiness of the entire command, it's possible that when you ran the command, one of the command options/flags did not have a space either before or after it which confused the interpreter. It probably goes without saying, but make sure you replace the USERNAME, OLDPASSWORD and NEWPASSWORD placeholders with the actual values before running the command.

Fillard Millmore
  • 326
  • 1
  • 11