How do I use chmod to change permissions? - readonly

I want to enable Remote Connections to MySQL on 1&1
i followed their explanation
https://help.1and1.com/servers-c37684/dedicated-server-linux-c37687/administration-c37694/enable-remote-connections-to-mysql-a781586.html
but the file system is Read-only.
with ls -l ==>
drwxr-xr-x 3 root root 4096 Nov 8 16:43 mysql
inside this folder mysql i have this file
-rw-r--r-- 105 root root 3533 Oct 22 2015 my.cnf
with ls -alt
***drwxr-xr-x 88 root root 4096 Nov 8 16:52 ..
drwxr-xr-x 3 root root 4096 Nov 8 16:43 .
-rw-r--r-- 105 root root 3533 Oct 22 2015 my.cnf***
I want to modify this file with chmod
but i have this error
chmod: changing permissions of 'my.cnf': Read-only file system
How to make a my.cnf writable? and after modification make it readable
Thanks

If a filesystem has been mounted read-only, chmod will not work since it's a write operation too.
sudo mount -o remount,rw '/mnt/yourmounthere'
If the device has a write lock on it (like SD memory cards), you need to turn it off. Hardware locks cannot be disabled by software. Note that the write lock on SD memory cards is located from the sight you see the letters near the up left corner and it looks like a very small switch.

"sudo chmod 777 my.cnf" for change like root user

Related

Messed up my bash_profile and bashrc files - reset to default?

I think I messed up my .bash_profile and .bashrc file.
Is there any way I can reset them to default?
When I want to access them through the terminal I get: Permission denied.
If I open them using sublime text, my .bashrc is completely empty and my .bash_profile contains the following code:
PATH="/Library/Frameworks/Python.framework/Versions/3.8/bin:${PATH}"
export PATH=/usr/local/bin:$PATH
alias python=python3
alias sublime="open -a /Applications/Sublime\ Text.app"
source ~/.profile
Any idea on what I could add/delete to any of the files?
Python does not run properly anymore since I accidentally played around on those files.
You may find the default .bash_profile and .bashrc files in /etc/skel/
[user#server /]$ ls -la /etc/skel
total 28
drwxr-xr-x. 3 root root 78 Jan 3 2019 .
drwxr-xr-x. 131 root root 12288 Nov 7 13:03 ..
-rw-r--r--. 1 root root 18 Oct 30 2018 .bash_logout
-rw-r--r--. 1 root root 193 Oct 30 2018 .bash_profile
-rw-r--r--. 1 root root 231 Oct 30 2018 .bashrc
If it's the case you can get them back:
cp /etc/skel/.bash_profile /etc/skel/.bashrc ~/
Make a backup of your current files before ;)
Just to explain: the content of /etc/skel/ is copied into the home directory of a user when created with adduser.

Setting permission for mounted folder - How to add write permission for group?

I mounted my windows device's folder to a ubuntu instance and cannot grant it group write permission:
drwxrwxr-x 2 user user 4096 Jul 15 10:25 new
drwxrwxr-x 4 user2 user2 4096 Jul 16 22:10 downloads
drwxr-xr-x 2 vidsuser vidsgroup 20480 Jul 17 08:31 archives
I tried a couple things eg:
sudo chgrp -R vidsgroup .archives
sudo chmod g+w ./archives
sudo chmod g+rwx ./archives/
the archives folder is the mount point and I cant change the permissions for this. What could I do?

Set runtimepath for vim in command line alias

I want to set an alias for vim so that when I use vim I want all my personal vim files to be sourced. (I want to do this because the machine I use is used by everyone else, so I don't want to affect others' usage. The alias is also set only when I login into the machine)
alias vim='vim -c "source ~/.dc_dotfiles/.vimrc_dc" --cmd "set rtp+=~/.dc_dotfiles/.vim"'
But this is not working as files in ~/.dc_dotfiles/.vim are not being sourced.
Here are the contents of ~/.dc_dotfiles/.vim folder
~$ ls -lhart .dc_dotfiles/.vim/plugin/
total 20K
-rw-r--r-- 1 veveo veveo 18K Oct 18 17:34 abolish.vim
drwxr-xr-x 3 veveo veveo 19 Oct 18 17:35 ..
drwxr-xr-x 2 veveo veveo 24 Oct 18 17:35 .
When I am using the screen I set a flag that will let know if I am logged in. I added this part to my ~/.vimrc
if !empty($DCSCREENFLAG)
set rtp+=~/.dc_dotfiles/.vim
endif
If the flag is set, it means that I am logged in and using the screen, so go ahead and add the directory to the runtimepath.

Dockers: external drive as shared volume in OSX, Permissions

First let me describe the system that I'm working on.
Intro
I've got a Mac with a small SSD drive. The system contains different
tools for data analysis that run as separated dockers.
Docker for OSX does not run directly on the system and it requires a
linux-based Virtual Machine which runs the dockers internally.
Some of these tools store huge amounts of data (several TB), which means that the internal HDD would not be enough so we need to store the data in an external media.
Therefore, for each docker it would be interesting to separate the data storage (databases) and the system files (OS + tool sources). Databases must be stored at the external HDD.
What I've done is:
Create a shared directory at the external HDD between OSX and the Linux-based VM (host for the dockers). Let's say that this directory is mounted at "/data" within the Linux VM.
Then, when creating a docker, use the "/data" directory from host as a volume mounted at the "/data" directory of the docker. If I ssh to one of the created dockers and list the content of the "/data" dir, I can see the content of the external HDD. So that works.
Here is when the problem appears, and it is related with PERMISSIONS.
PROBLEM
Considering that:
At the OSX our user is peterfoo
At the dockers the main user is also peterfoo, but we may have secondary users for the different system services. For example, if we install MYSQL, the MySQL service will be executed by default by the user mysql and all the files will belong to this user.
I want to change the MySQL data directory to enforce that all the data is stored at the "/data" directory (i.e. at the external HDD)
If I user the user peterfoo there is not problem: I can write files, read files, remove and create directories, etc. at the "/data" directory (external HDD) from the docker. However, using a different user the system does not allow writting, which means that when the mysql user tries to write/read data from the new location it fails and MySQL stops working.
SOLUTIONS?
I couldn't find a solution at this forum and I've being trying to fix this issue from yesterday.
The only solution that I found for the moment is a really naive one: run the MySQL (and other services) as the peterfoo user, instead of the correspoding one (mysql). This is not a critical issue but introduces a security problem: it is always recomendable to use specific users for the system services to keep control of the access to data.
Any idea?
Thanks!!
More info
If I run ls -l to /data directory, I get:
drwxr-xr-x 8 peterfoo staff 272B 17 may 09:48 app1-data/
drwxr-xr-x 3 peterfoo staff 102B 25 may 12:38 app2-data/
drwxr-xr-x 7 peterfoo staff 238B 25 abr 10:35 app3-data/
If I try to change the ownership of the directory to mysql, it doesn't work and keeps peterfoo.
$ sudo chown mysql:mysql /data/app1-data
$ ls -l /data | grep app1
drwxr-xr-x 8 peterfoo staff 272B 17 may 09:48 app1-data/
If also tries changing the rwx permissions to 777 and then using a secondary user (let's say user2) can create dirs and files but once created, the ownership changes automatically to peterfoo, and the created subdirectories become unwritable to user2.
$ sudo chmod 777 /data/app1-data
$ ls -l /data | grep app1
drwxrwxrwx 8 peterfoo staff 272B 17 may 09:48 app1-data/
$ su user2
$ touch test.txt
$ mkdir /data/app1-data/test
$ ls -l /data/app1-data/
drwxrwxrwx 1 peterfoo staff 204 May 25 12:38 ./
drwxrwxr-x 1 peterfoo staff 510 May 24 14:29 ../
-rw-r--r-- 1 peterfoo staff 0 May 25 08:07 test.txt
drwxr-xr-x 1 peterfoo staff 68 May 25 12:38 test/
Uhm let me get this straight:
you got a virtual machine for linux to wich you attached part of the external storage; you then mounted that storage at /data in linux system.
created a docker container with a volume at /data inside the container mounted at /data inside the linux vm.
if i got that right the docker should automatically have permission to write in /data at linux vm and the only problems i can think of are the permission that are set inside the docker at the /data directory.
if my hunch is right when you ssh inside the docker and ls -l at / you will find owner is peterfoo and lacking permission for other users

Unable to make file editable on Mac OS X

I'm trying to edit the httpd.conf file located in /private/etc/apache2, and I can't figure out how to get permission to write
I've done
$ cd /private/etc/apache2
$ sudo chown bdh httpd.conf
$ ls -lash
0 drwxr-xr-x 13 root wheel 442B Jun 7 00:11 .
0 drwxr-xr-x 93 root wheel 3.1K Jun 26 10:51 ..
0 drwxr-xr-x 13 root wheel 442B Jan 3 16:26 extra
24 -r--r--r-- 1 bdh wheel 24K Jun 7 00:11 httpd.conf
...etc...
$ vim httpd.conf
and it says "httpd.conf" [readonly] 677L, 24330C
tried cping to the desktop, but I cant get permission to edit it there either
I'm pretty new to using the terminal, is there some other command I can use?
It is normally unnecessary and undesirable to alter access permissions to edit a file. To edit a file that requires administrator (or other user) privileges without altering the access permissions, use:
sudo -e /private/etc/apache2
Sudo's -e option tells it you want to edit the given file.
This command copies the file and makes it writable by you, tells the editor specified with the SUDO_EDITOR, VISUAL or EDITOR environment variables (they're checked in that order) to edit the file, and when the editor exits, the file is copied back to the original without altering its access permissions.
See the sudo man page for details: x-man-page://8/sudo
The chmod command is what you're looking for I believe: http://en.wikipedia.org/wiki/Chmod
chmod 777 will let anyone read, write or execute for instance.
As richardhsu correctly added, 744 is RWX, R--,R-- and thats probably what you want.

Resources