**Step 1: Create the Linux User**
- Create a new user on the Linux system using the `adduser` or `useradd` command:
```bash
sudo adduser admin_user
```
Replace "admin_user" with the desired username for the admin user.
**Step 2: Assign Database Access**
- For each database, you'll need to grant the admin user appropriate privileges. Here's a high-level overview for three common databases:
**MySQL/MariaDB:**
- Access the MySQL shell as a privileged user:
```bash
sudo mysql
```
- Create a new user and grant privileges:
```sql
CREATE USER 'admin_user'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON database1.* TO 'admin_user'@'localhost';
GRANT ALL PRIVILEGES ON database2.* TO 'admin_user'@'localhost';
GRANT ALL PRIVILEGES ON database3.* TO 'admin_user'@'localhost';
FLUSH PRIVILEGES;
```
**PostgreSQL:**
- Access the PostgreSQL prompt as a privileged user:
```bash
sudo -u postgres psql
```
- Create a new user and grant privileges:
```sql
CREATE USER admin_user WITH PASSWORD 'password';
GRANT ALL PRIVILEGES ON DATABASE database1 TO admin_user;
GRANT ALL PRIVILEGES ON DATABASE database2 TO admin_user;
GRANT ALL PRIVILEGES ON DATABASE database3 TO admin_user;
```
**MongoDB:**
- Access the MongoDB shell:
```bash
mongo
```
- Switch to the admin database and create a user with appropriate privileges:
```javascript
use admin
db.createUser(
{
user: "admin_user",
pwd: "password",
roles: [ { role: "readWrite", db: "database1" }, { role: "readWrite", db: "database2" }, { role: "readWrite", db: "database3" } ]
}
)
```
**Step 3: Test Database Access**
- After setting up the database access, you can test the admin user's access to the databases using the respective database clients or command-line tools.
By following these steps, you can create an admin user on a Linux system with access to three different databases. Be sure to replace "admin_user" and "password" with your desired username and password, and adjust the database names and privileges to match your specific environment.
1 минута
27 марта 2024