How to edit read only file, as root without sudo - ssh

I have a thecus home server, I'd like to edit the index.php file located under /img/www/htdocs/index.php however it tells me every time I vi that it's 'Read-only'.
I checked it's file permissions using ls -l index.php:
-rw-r--r-- 1 root root 7619 Mar 29 2013 /img/www/htdocs/index.php
From my understanding, the -rw first in the permissions, stands for the ownership permissions, and the owner is root in the group of root.
I have ssh'd into my server using:
ssh root#server.com
Once I login, it say's
root#127.0.0.1:~#
I have tried changing it's ownership, chmodding it, using vi to change permissions, trying to force it doesn't work either, how can I edit this damned file ! :(
When I try to use sudo it say's the command is not found, so I'm assuming that's because Thecus have stripped down the commands.
The output of mount without any arguments, I have noticed that the directory that I'm currently working in, is actually set to ro, is there a way I can edit this?
/dev/cloop2 on /img/www type ext2 (ro,relatime,errors=continue,user_xattr,acl)
Any help would be great! :)

Try mount -o remount,rw /img/www/, if that is not possible, you can copy the contents to a place where you can modify them, unmount the original /img/www/ and then symlink or "bind mount" the new location there.

Related

ls doesn't show any output in ssh connected to an Debian 9 VM instance in Google Cloud Platform

this might be a dumb question, but I checked everywhere and there's no direct answer to it.
I set up both SSH keys successfully and I can connect to my instance via terminal, but when I do "ls", it doesn't show me any output. I am using iTerm2 with zsh on my Mac but I don't think this is an issue.
Can anybody give me a hint? Thanks!
When you access a VM through SSH, your working directory is the home directory of the user specified with the SSH command, i.e. /home/username. In case you access as root, the working directory will be /root.
You can check it through the command pwd
If it is a brand new machine, it is normal that the output of 'ls' is empty since in your home directory no file matches the filters of 'ls' with no parameters. The reason is that 'ls' doesn't show filenames starting with a dot ('.') because in the Linux convention they are hidden unless you run ls -al.
You can try again with $ ls -al and you will be able to see hidden files and directories as well.
On the other hand you can create as well first an empty file and then running again 'ls':
$ touch file
$ ls

nfsnobody User Privileges

I have setup an NFS file share between two CentOS 6, 64 machines. On the server the folder being shared was originally owned by the root user. On the client it turned up as being owned by nfsnobody. When I tried to write to the folder from the client I got a permissions error. So I changed the folder ownership on the server to nfsnobody and chmod'd it to 777. However, still no joy - I continue to get a permissions error. Clearly, there is more to this. I would be much obliged to any Linux gurus out there (I personally wouldn't merit being called anything more than a newbie) who might be able to help fix this issue.
Edit - I should have mentioned that trying to write to the shared folder from the client actually manages to create a file entry. However, the file size is 0 and the permissions error is reported.
The issue here is to do with the entry in /etc/exports. It should read
folder ip(rw,**all_squash**,sync,no_subtree_check)
I had missed the all_squash bit. That apart, make sure that the folder on the server is owned by nfsnobody. On my setup both my client and server nfsnobodies ended up with a user id if 65534. However, it is well worth checking this (/etc/groups) or else... .
Here are a couple of useful references
How to setup an NFS SErver
NFS on CentOS
For the benefit of anyone looking to setup an NFS server I give below what worked for me on my CentOS 6 64bit machines.
SERVER
yum install nfs-utils nfs-utils-lib - install NFS
rpm -q nfs-utils - check the install
/etc/init.d/rpcbind start
chkconfig --levels 235 nfs on
/etc/init.d/nfs start
chkconfig --level 35 rpcbind on
With this done you should create the folder you want to share
mkdir folder
chown 65534:65534 folder
chmod 755 folder
Now define the folder to be shared/exported. Use your favorite text editor (vi or whatever) to
open/create /etc/exports
folder clientIP (rw,all_squash,sync,no_subtree_check)
Client
Install, check, bind and start as above
mount -t nfs serverIP:folder clientFolderLocation
If all goes well you should now be able to write a little script on your client
<?php
$file = $_SERVER['DOCUMENT_ROOT']."/../nfsfolder/test.txt";
file_put_contents($file,'Hello world of NFS!');
?>
browse to it and find that test.txt now exists on the server with the content "Hello world of NFS". In the example I have placed my mounted drive one level before document_root.

#1 - Can't create/write to file '/var/folders/

I get the following error(see. figure) in my Xampp and can not access mySQL through XAMPP and phpMyAdmin. In this link-1 and link-2 possible solution is given; but none of them woks in Mac OS 10.9
I assume the problem is with configuration file my.cnf which is located in the /Applications/XAMPP/xamppfiles/etc/my.cnf.
Any suggestion will be appreciate. Thanks.
Completely stop XAMPP, this means stop apache, ftp and mysql.
Open the program called Terminal.
Type in sudo -i to become root (or do su root if the first doesn’t work for you).
You are most probably asked for a password which you have to enter while no characters are displayed.
Execute chmod 600 /Applications/XAMPP/xamppfiles/etc/my.cnf .
Exit your root shell with exit or just close Terminal.
Restart XAMPP (apache, ftp and mysql).
From: http://slopjong.de/2009/08/31/houston-i-cant-write-to-file/
Solution
Reinstall Xampp. Before reinstalling delete all the files, take away your htdoc and database folder to other place of your hdd.
The database location in Mac OS-10.9 is
cd '/Applications/XAMPP/xamppfiles/var/mysql/'
Htdoc location
cd '/Applications/XAMPP/xamppfiles/htdocs/'
When you complete reinstallation put all the folders to corresponding location and your database will be automatically update.
I looked some other solution but none of them seems work. I was scare if I remove the database to other location and import later will it work or not. And luckily it works, but as precaution careful when you remove big database.

PSCP copy files from godaddy to my windows machine

I want to take backup of my website which is hosted on godaddy.
I used pscp command from my windows dos and try to download whole public_html folder.
my command is :
pscp -r user#host:public_html/ d:\sites\;
Files are downloading properly and folders also. But the issue is public_html and other subfolders has two folder like "./" and "../". Due to these two folders my copy is getting failed and I am getting
"security violation: remote host attempted to write to " a '.' or '..' path!"error.
Hope any one can help for this.
Note : I have only ssh access and have to download it from ssh commands itself.
Appending a star to the source should fix it, e.g.
pscp -r user#host:public_html/* d:\sites\;
Also you can do same thing by not adding '/' at the end of your source path.
For eg.
pscp -r user#host:public_html d:\sites
Above command will create public_html directory if not exists at your destination (i.e. d:\sites).
Simply we can say using above command we can make a as it is clone of public_html at d:\sites.
One important thing: You need to define the port number over here "-P 22".
pscp -r -P 22 user#host:public_html/* D:\sites
In my case, it works when I use port number 22 with the above script.

Postfix piping email to php, permissions error

I'm attempting to pipe an email to PHP with my Postfix mail server, using the technique mentioned here and have encountered the following error...
Mar 16 22:52:52 s15438530 postfix/pipe[9259]: AD1632E84C63: to=<php#[myserver].com>, relay=plesk_virtual, delay=0.61, delays=0.59/0/0/0.02, dsn=4.3.0, status=deferred (temporary failure. Command output: /bin/sh: /var/www/vhosts/[myserver].com/httpdocs/clients/emailpipe/email2php.php: Permission denied 4.2.1 Message can not be delivered at this time )
I'd really appreciate if anyone could shed some light on this issue for me. I've tried 777'ing the emailpipe directory, to no avail. Where am I going wrong?
Many thanks.
From the postfix docs...
For security reasons, deliveries to command and file destinations are performed with the rights of the alias database owner. A default userid, default_privs, is used for deliveries to commands/files in root-owned aliases.
So you have two options, either set the default_privs in main.cf to match the ownership of the email2php file.
Alternatively, there should be a way to create an alias database that is owned by the user instead of postfix/nobody. I haven't tried this before though so can't advise.
I have fixed this issue by disabling the SELINUX.
Make sure that you have
#!/usr/bin/php
<?php
(or whatever your path to php is - do "which php" on the server)
at the top of each of your php scripts and that each of the php script files is executable
chmod +x /var/.../email2php.php
Also, make sure that you can test the script from the command line:
cat some_rfc822_email.txt | /var/.../email2php.php
and get the result that you want
To fix this issue, you'll want to chown or chmod /var/www/vhosts/[myserver].com/httpdocs/clients/emailpipe/email2php.php to executable by your postfix user. Alternately, you'll want to redefine this user to execute the file successfully.
Simply changing the permissions of your directory (unless you used -R) won't be sufficient.
To illustrate why this works, consider the following toy example:
<me>#harley:~$ touch test
<me>#harley:~$ ls -al test
-rw-r--r-- 1 <me> <me> 0 2012-03-26 23:44 test
<me>#harley:~$ sh test
<me>#harley:~$
<me>#harley:~$ ./test
bash: ./test: Permission denied
<me>#harley:~$ chmod 755 test
<me>#harley:~$ ./test
<me>#harley:~$
In order to execute a file directly through the running shell, it needs to be set as executable. Other invocations (for example, sh email2php.php or php email2php.php) only require read access, because they're chaining execution off a different file entirely.
For what's likely to be causing the issue in the first place, see here.