Bash Script Task Review Error -

My mistake. I forgot to add point #2 in my previous steps to make the .zip file executable for others.

Although I added x permission to others when you reassigned the task to me, that is the reason Banner user was able to execute the .zip file.

So the script will have the below commands:

  1. Archive the news dir - zip /backup/xfusioncorp_news.zip -r /var/www/html/news
  2. Add x permission to others - chmod o+x /backup/xfusioncorp_news.zip
  3. Finally secure copy the file - scp /backup/xfusioncorp_news.zip clint@stbkp01:/backup/

Repeat the steps again with point #2 as well and you will be able to run the .zip file from either of the three App Server Users.

Hi @avnimahesh,
I think you are not getting my point.
User tony has to enter a password each time whenever he will execute the script. This is not a passwordless setup for him.
You need to copy his public key to the backup server first by using the ssh-copy-id command. After that, he will be able to run the script without entering the password.
I think you did the same for the root user right?

In the task, we only need to copy the zip file to the respective server. We didn’t say that users have to unzip as well. So don’t require that permission change for the zip file.

Regards,

Please refer to point d in the question to understand the below points.

Point d. in the image below

image-421

I don’t think that the question is asking to make App Server users to be able to login password-less to the Backup Server.

It only says, “make sure script won’t ask for password while copying the archive file.” So in order to fulfil the password-less copying from one server to another, I had to setup a password-less ssh login between those two servers which I did.

I could have copied the public key of Tony user but I would have to perform all the tasks with SUDO privileges only right because all the directories were in the / location which a normal user is denied access to.
So instead of doing sudo sudo in every command, I simply switched the user and did all the steps.

So even if I did →
[logged in as Tony user]
sudo vi /scripts/scriptname.sh

OR

[logged in as root in App Server 1]
vi /scripts/scriptname.sh

the ownership for the script file would be root user only. So there was no sense doing all the tasks being a normal user on App Server 1.

Secondly, it says,“Additionally, the respective server user (for example, tony in case of App Server 1) must be able to run it.” ----> The question would obviously not refer to password-less login to Backup server by saying the word “run it”. The question is referring to the file which is on the backup server.

Yeah, it is a pain for the users to enter the password every time they login to the Backup Server but the question didn’t asked to make Users for password-less login to Backup Server or else it is only a single command thing to do.

So as per the above explanation, the .zip file must have an (x) permission on others so that our users from App Server 1, 2 and 3 could run the file.

Also I want to highlight something. We totally forgot the problem here while discussing.

The problem is "Kodekloud’s verification system was not able to find the .zip file copied by the script on the Backup Server."

The problem was nowhere around what the permissions were or are users able to run the file or not.

See the picture below —

Image 1

Image 2

image

Image 3

THESE ARE THE IMAGES FROM MY FAILED TASKS.

I hope you understand.

But you haven’t mentioned in the above comments. If you did then it should work without any issues. Because I did the same and validation got passed.

It’s a task and we can’t specify each step right? We need to think accordingly about how to complete the task.

We are only saying for the script which is “/scripts/xxxxxxx.sh”.

  1. We are archiving the directory /var/www/html/beta.
  2. Then we are using the scp command to copying a file to the target server
    so we need to set up the passwordless login for the respective user of that app server so it won’t ask password when we’ll run the script because after submitting the task, validation runs your script and it will get stuck due to asking for the password.

It did well but the respective user (tony) of that server was able to run the script but was stuck because of the password (as I showed in the above screenshot) so the file was not copied successfully. So that’s why the system was not able to find the archive file on the backup server.

Regards,

Okay…

I am not sure what was the issue because I again followed the same steps when you re-assigned the Task to me, and it passed.

Well, thanks for your time and efforts.

Regards,
Avni Maheshwari