用户管理与角色
学习创建和管理用户、分配角色,并在 Neo4j 中定义自定义访问权限
用户管理与角色 是 CoddyKit 上的免费 Neo4j Graph Database Fundamentals 课时。 这是第 1 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Neo4j Graph Database Fundamentals 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Neo4j Graph Database Fundamentals 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Secure Your Graph Data
Welcome to securing your Neo4j database! Just like any valuable asset, your graph data needs protection.
This lesson introduces the essential steps to manage who can access and modify your Neo4j database.
Control Access to Your Data
Why bother with user management? Imagine a bank vault without proper access control – chaos!
- Security: Prevent unauthorized access.
- Accountability: Track who does what.
- Compliance: Meet regulatory requirements.
It's about making sure only the right people have the right permissions.
AuthN vs. AuthZ
These terms are often confused, but they're distinct:
- Authentication (AuthN): Who are you? This verifies a user's identity (e.g., username and password).
- Authorization (AuthZ): What can you do? This determines what actions an authenticated user is allowed to perform.
First, we prove who we are (AuthN), then the system decides what we can do (AuthZ).
Meet the Default Admin
When you first install Neo4j, a default administrative user named neo4j is created.
- It has full administrative privileges.
- The initial password is also
neo4j. - Important: Always change this default password immediately after installation for security!
This user is your entry point to managing the database.
Adding New Users
To add new individuals or applications to your database, you'll create new user accounts.
Each user needs a unique username and a strong password. This ensures proper authentication before any actions are taken.
Let's see how to do this using Cypher, Neo4j's query language.
Creating Users with Cypher
The CREATE USER command is straightforward. Remember to choose a secure password!
Try running this example in your Neo4j Browser or cypher-shell:
CREATE USER 'alice' SET PASSWORD 'securePassword123';Changing Passwords
Passwords should be changed regularly, and users might forget them. Neo4j provides commands to manage user passwords.
- Change your own password:
ALTER CURRENT USER SET PASSWORD 'newPassword'; - Change another user's password (admin only):
ALTER USER 'alice' SET PASSWORD 'anotherNewPass';
Always use strong, unique passwords!
What are Roles?
Roles are collections of privileges that can be assigned to users. Instead of giving individual permissions to each user, you assign them a role.
Neo4j comes with several built-in roles, such as:
admin: Full administrative access.architect: Can create/manage schema (nodes, relationships, properties).publisher: Can write data.reader: Can only read data.
This simplifies managing permissions across many users.
Granting Roles
Once you've created users and understand roles, the next step is to grant specific roles to users. A user can have multiple roles.
Use the GRANT ROLE command to assign roles. To remove a role, use REVOKE ROLE.
Let's grant our new user 'alice' the 'reader' role:
GRANT ROLE reader TO alice;Check Your Understanding
You've learned how to create users and assign roles. Let's test your knowledge!
Lesson Summary
Great job! In this lesson, we covered the fundamentals of user management and roles in Neo4j:
- The importance of authentication and authorization.
- How to create new users using
CREATE USER. - Managing user passwords with
ALTER USER. - Understanding built-in roles like
admin,reader, andpublisher. - Assigning roles to users with
GRANT ROLE.
This knowledge is crucial for securing your graph database! Next, we'll dive deeper into defining custom access privileges.
常见问题解答
「用户管理与角色」课时是免费的吗?
是的 — 「用户管理与角色」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Neo4j Graph Database Fundamentals 课程的其余内容,请升级到 CoddyKit PRO。 Neo4j Graph Database Fundamentals 课程共包含 4 节课。
「用户管理与角色」这节课中我会学到什么?
学习创建和管理用户、分配角色,并在 Neo4j 中定义自定义访问权限 你通过在浏览器中直接运行的动手代码来练习 Neo4j Graph Database Fundamentals,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Neo4j Graph Database Fundamentals 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Neo4j Graph Database Fundamentals 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 1 节课,共 4 节。
「用户管理与角色」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Neo4j Graph Database Fundamentals 课中编写并运行代码吗?
能。每节 Neo4j Graph Database Fundamentals 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- 用户管理与角色
- 身份验证与授权
- 保护 Neo4j 部署
- 细粒度访问控制与审计