0

Well, I am new to Linux. And I have done something stupid enough to get me into trouble.

So the thing is that I have an AWS account, and was working fine except for my PDF rendering service. I figure out it had something to do with file permissions.

So, I used the following commands:

cd /var/

find . -type d -exec chmod 0775 {} \;

find . -type f -exec chmod 0644 {} \;

The PDF rendering issue got solved, but now I can't connect to my server neither with Filezilla nor putty.

I know that I have to change my /var file permission to 755. But I don't know where to change that.

What should I do next so that I can connect to my server?

If I create a new key-pair for my existing instance, can then I ssh through putty?

1
  • You should not be messing with the permissions of an entire filesystem when you are new to an OS.... Is this the Amazon linux distro or something else? Apr 19, 2018 at 12:29

2 Answers 2

0

Since you don't have access to the VM currently: If you are using an EBS volume, you can power off the instance and connect the disk to another instance. You then need to mount the disks into a directory (say /recover) and chroot into that directory. You can then attempt other recovery processes.

If it is simple partitions, the mounts should not be especially hard. (If you know enough to install Arch or [Gentoo])(https://wiki.gentoo.org/wiki/Handbook:X86/Installation/Disks) ) (It is probably /dev/sdb*). If LVM is involved, it becomes more complicated... Starting with ls /dev/sd* and mount /dev/partition /recover is a start... But getting someone that knows what they are doing might be a good idea...

Once you have a prompt in the instance: If it is running the Amazon distro, or another RPM based distribution, start by resetting the permissions to the values from the rpm packages using: (via)

for p in $(rpm -qa); do rpm --setperms "$p"; done
for p in $(rpm -qa); do rpm --setugids "$p"; done

Removing group write permissions from all files with chmod 644 likely prevents whatever FTP server you have and OpenSSH from writing to files in /var used to keep track of sessions. (OpenSSH is also paranoid and refuses to do things if security might be compromised due to too wide permissions (like the 775 permission on all directories))

Afterwards, try and figure out what permissions the faulty application want (for command-line applications, you can check which system calls fail with permission issues with truss or strace, otherwise, you might need to set up auditing to see the failed access attempts) and change the minimal permissions to get it working. (SELinux might be a factor as well, audit2why and audit2allow can tell which policies are involved and how to fix them)

6
  • Hi, Gert Thanks for answering.But My point is that I can't access anything right now.The server just won't let me connect to it.You're Right that the permissions such as 775 are too broad.But Now what should I do. I need to run this command cd /var/ find . -type d -exec chmod 0755 {} \; .But the point is I can't connect with any terminal now. Apr 19, 2018 at 12:46
  • @AnkitRauthan: The problem is that you need KVM type access to the VM. For physical servers, this would mean plugging in a keyboard and a screen, with VM's this usually means opening a console on the VM. Amazon does not offer this. What instance type is it? Apr 19, 2018 at 12:55
  • the Instance type is:- t2.xlarge Apr 19, 2018 at 13:02
  • @AnkitRauthan: OS on EBS or instance storage? Instance storage gets tricky.... Apr 19, 2018 at 14:12
  • My OS is on EBS Apr 19, 2018 at 14:26
-1

@Gert Thanks mate, your answer show me the way that how can I solve this problem. Well, I will not say that my way is right because I knew that what the problem was exactly, and that's how I tackle it.You can take the idea and can do it according to your problem.

So Here is what I did:-

1) Create a new AWS Instance say Demo Instance.

2) Stop your original Instance say Production Instance.

3) Now, Detach your production volume from your production Instance.

4) Attach your production volume with your demo Instance.Device name will be /dev/sdf(by default don't change it).

5) Now In putty create a new connection with demo Instance.

6) Now Follow these Commands:-

sudo su (Get Root Privilage)
mkdir /mnt/tmp (Create Directory)
lsblk (To check the disks)
mount /dev/xvdf1 /mnt/tmp (To access the original volume)
cd /mnt/tmp/var/ (Get Into The Var directory Of The original volume)
find . -type d -exec chmod 0755 {} \; (Change Permissions Of The var 
                                       directory,Which was the main problem 
                                       due to which I was Unable To SSH Into 
                                       my server)
umount

7) Stop your demo instance,Detach your original volume from demo instance.

8) Attach Your original volume with production instance,Start The Original Instance.

9) Now I was again able to ssh into my server.

Thanks, Gert it was because of your answer and drive mounting solution, I was able to solve this problem.Cheers

2
  • 1
    Replacing the incorrect permissions with other incorrect permissions isn't really the way to go. There is no way 755 is going to be correct for all directories, any more than 775 was.
    – tripleee
    Apr 24, 2018 at 9:09
  • Well The thing was that i was unable to ssh to my server,which was the main problem.I'm not saying that the permissions are right now.I am seeing on that part.But Now I can ssh into my server. Apr 24, 2018 at 9:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .