how to open /dev/mem in non-root mode? - linux

I tried to open /dev/mem.
Accessing /dev/mem needs root permission to open the file.
But I can't use my program in super user. so I changed /dev/mem access permission as 666(Don't consider about security issues!). but still, I cant open the file.
is there any way to open the file in non root mode?

No, there is not. Access to /dev/mem is a privileged operation.

Have you tried adding your user to kmem group?
If you need just read permission it may work.

At your file change the owner and set permissions 4755.
sudo chown root FILE
sudo chmod 4755 FILE

Related

change permissions on a not writable

UPDATE:
I moved my question to ask ubuntu community, but can not delete it from here... if you have an awenser, please share it on ubuntu community not here... Thanks
i want to make an change on a file but i cant do that because i have not correct permissions:
➜ ls -l pycharm64.vmoptions
-rw-r--r-- 1 root root 427 Dec 28 18:33 pycharm64.vmoptions
i tried to change permisions by these two command:
sudo chmod a+w pycharm64.vmoptions
and
sudo chown user:user pycharm64.vmoptions
but in i get an erro both time:
Read-only file system
how can i make an change on my file? (honestly i dont care about the owner and groups of the file... i just want to change my file anyway)
P.S: my OS is UBUNTU
You can change a file on read only by setting the "immutable property"
chattr +i [fileName]
If you want to revert it just change the "+" for a "-"
chattr -i [fileName]
Your filesystem could be mounted as read only. You have to change first before you can write anything to it. Changing file permissions also requires writing on the filesystem.
You may be able to mount it as read write with command like:
sudo mount -o remount,rw /dev/foo /mount/destination/dir
In this command you spesify that you want to remount the filesystem with different options, adding the readwrite, rw capability.
If you successd in changing the filesystem to read write, then you should be able to change to file permissions with the commands you tried earlier.
You can`t edit it directly (I'm not sure about Windows).
You should edit custom settings file instead:
Manually
nano ~/.config/JetBrains/PyCharm2022.3/pycharm64.vmoptions
or from IDE -- https://intellij-support.jetbrains.com/hc/en-us/articles/206544869.

Restrict access on a mounted device (Linux)

The challenge is to allow access to only one directory on the mounted device for all users.
I have an external hard drive. I mount it using the command
sudo mount -o umask=0007,gid=0,uid=0 /dev/sdb1 /mnt/SAMSUNG/
I need to make one directory available for reading/writing to other users on this device. I cannot do this via sudo chmod 777 /mnt/SAMSUNG/my_directory, the command has no effect.
Is there some other way to do this? Maybe I'm doing something wrong?
When mounting the NTFS file system (/mnt/SAMSUNG/), there is no possibility of mounting a specific directory.
In your sudo chmod 777 /mnt/SAMSUNG/my_directory command you give
The user, rwx (Read, Write and Execute) permissions
The group, rwx permissions
And Everyone else rwx permissions
Inside of /mnt/SAMSUNG/my_directory is the thought that there should be more directories that is specific for other accounts?
If that is the case and the users are local you could do something like this:
sudo chown someuser:someuser /mnt/SAMSUNG/my_directory/someusersdir && sudo chmod 770 /mnt/SAMSUNG/my_directory/someusersdir

Normal user touching a file in /var/run failed

I have a program called HelloWorld belonging to user test
HelloWorld will create a file HelloWorld.pid in /var/run to keep single instance.
I using following command to try to make test can access /var/run
usermod -a -G root test
However, when I run it, falied
could someone help me?
What are the permissions on /var/run? On my system, /var/run is rwxr-xr-x, which means only the user root can write to it. The permissions do not allow write access by members of the root group.
The normal way of handling this is by creating a subdirectory of /var/run that is owned by the user under which you'll be running your service. E.g.,
sudo mkdir /var/run/helloworld
sudo chown myusername /var/run/helloworld
Note that /var/run is often an ephemeral filesystem that disappears when your system reboots. If you would like your target directory to be created automatically when the system boots you can do that using the systemd tmpfiles service.
Some linux systems store per-user runtime files in /var/run/user/UID/.
In this case you can create your pid file in /var/run/user/$(id -u test)/HelloWorld.pid.
Alternatively just use /tmp.
You may want to use the user's name as a prefix to the pid filename to avoid collision with other users, for instance /tmp/test-HelloWorld.pid.

How find out who is the owner of a program?

I'm studing Set-UID Privileged Programs, and it seems that a program executes with a its own owner privilegies.
Example: passwd can read/write the shadow file because it belongs to a root user. How can i find this kind of information for other programs?
When you set user identification (the 4755 mode) permission to an executable file, a process that runs this file is granted access based on the owner of the file.
In this case you copy /bin/zsh as root user and then set the 4755 mode, /tmp/zsh so will give root privileges to the user that will run the file rather than user privileges.
This special permission allows a user to access files and directories that are normally only available to the owner.
Have you tried to make what you have been asked?
Use getuid(2), geteuid(2), getresuid(2) and the corresponding setuid(2), setreuid(2) appropriately. See also capabilities(7) and credentials(7) & carefully execve(2). Read about proc(5)
Read the Setuid wikipage. A process running a setuid executable can call seteuid to gain privilege.

File read permissions for 'others' not working

I'm trying to give read permissions to lighttpd access logfiles to normal users which are on the same system.
The permissions are currently:
-rw-r--r-- 1 www-data www-data 211K Feb 28 11:27 /var/log/lighttpd/access.log
So, if I understood correctly others have read permissions. Unfortunately this doesn't seem to work. If I try to read this file with an user account I get:
/var/log/lighttpd/access.log: Permission denied
I already tried to add the user to the group www-data which didn't work as well.
Any hints what I'm doing wrong here?
To access a file, the system needs the execute permission on all the directories containing the file.
In this case it was necessary to issue the chmod o+x /var/log/lighthttps command (after making sure that the user belongs to the "other" part of the permission set).
The "execute" permission for a directory allows you to enter it. The "read" permission for the directory allows you to see the names of the files inside. The interesting thing is that you can give the x permission alone, what means that anyone can access the files inside, but he needs to know its names.
You might not have execute permission for the lighthttpd so the directory does not give the permission to access its containing file.
Use the command to set the execute permission to that directory.
chmod +x /var/log/lighthttpd

Resources