知识库

如何不在命令行中指定用户名和密码来通过 cypher-shell 进行身份验证

在命令行使用 $NEO4J_HOME/bin/cypher-shell 并且通过设置 $NEO4J_HOME/conf/neo4j.conf 启用身份验证时

# Whether requests to Neo4j are authenticated.
# To disable authentication, uncomment this line
dbms.security.auth_enabled=true

可以在命令行使用参数 -u <username> -p <password> 提供用户名和密码。但也可以定义环境变量 NEO4J_USERNAMENEO4J_PASSWORD,例如

export NEO4J_USERNAME='neo4j'
export NEO4J_PASSWORD='password'

一旦定义了这些环境变量,就可以运行 $NEO4J_HOME/bin/cypher-shell 而无需在命令行上指定 -u 和 -p。这还有一个好处:当运行 Linux 的 'history' 命令(显示最近 N 条命令行调用)时,用户名和密码不会被泄露。

此外,如果使用 Linux,上述 export 命令可以放在用户主目录的 .bashrc 文件中(例如 /home/neo4j/.bashrc),且 .bashrc 会在首次登录时被调用。

如果使用 Windows,可以通过 Control Panel → System, Advanced tab, [Environment Variables] 来定义环境变量,如下图所示

image

© . This site is unofficial and not affiliated with Neo4j, Inc.