Creating a read-only user for rsync can be useful when you want to give someone access to your files without allowing them to make any changes. In this article, we will guide you through the process of setting up a read-only user for rsync.
Step 1: Create a New User
The first step is to create a new user on your system. This user will be used specifically for rsync and will have read-only access to your files.
- Open a terminal or command prompt.
- Run the following command to create a new user:
- Follow the prompts to set a password for the new user.
- Make sure to remember the password as you will need it later.
sudo adduser rsyncuser
Step 2: Configure SSH Access
Next, we need to configure SSH access for the new user. This will allow them to securely connect to your system and access the files.
- Open the SSH configuration file using a text editor. The file is usually located at
/etc/ssh/sshd_config. - Find the line that starts with
#PermitRootLoginand add the following line below it: - Save the file and exit the text editor.
- Restart the SSH service for the changes to take effect. The command may vary depending on your operating system. For example, on Ubuntu, you can run:
AllowUsers rsyncuser
sudo service ssh restart
Step 3: Configure File Permissions
Now, we need to set up the file permissions to ensure that the rsync user has read-only access to the files.
- Open a terminal or command prompt.
- Navigate to the directory where the files you want to share are located.
- Run the following command to change the ownership of the files:
- Replace
/path/to/fileswith the actual path to the directory. - Next, run the following command to change the file permissions:
- These commands will ensure that the rsync user has read and execute permissions on the files.
sudo chown -R rsyncuser:rsyncuser /path/to/files
sudo chmod -R 755 /path/to/files
Step 4: Test the Read-Only Access
Now that everything is set up, it's time to test the read-only access for the rsync user.
- Open a terminal or command prompt.
- Run the following command to connect to your system using SSH:
- Replace
your-server-ipwith the IP address or hostname of your server. - Enter the password for the rsync user when prompted.
- Once connected, navigate to the directory where the files are located:
- Run the following command to list the files:
- You should see a list of files in the directory. However, if you try to make any changes to the files, you will receive a permission denied error.
ssh rsyncuser@your-server-ip
cd /path/to/files
ls
Setting up a read-only user for rsync can help you securely share your files without worrying about unintended modifications. By following the steps outlined in this article, you can easily create a read-only user and ensure that your files remain safe.
| Reference | Link |
|---|---|
| rsync man page | https://linux.die.net/man/1/rsync |
| OpenSSH documentation | https://www.openssh.com/ |