LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   unable to cd into /var/log/audit (https://www.linuxquestions.org/questions/linux-newbie-8/unable-to-cd-into-var-log-audit-4175733815/)

mahesh.riddles 02-13-2024 08:31 AM

unable to cd into /var/log/audit
 
Code:

cat /etc/os-release
Code:

NAME="Fedora Linux"
VERSION="39 (Workstation Edition)"
ID=fedora
VERSION_ID=39
VERSION_CODENAME=""
PLATFORM_ID="platform:f39"
PRETTY_NAME="Fedora Linux 39 (Workstation Edition)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:39"
DEFAULT_HOSTNAME="fedora"
HOME_URL="https://fedoraproject.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f39/system-administrators-guide/"
SUPPORT_URL="https://ask.fedoraproject.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=39
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=39
SUPPORT_END=2024-11-12
VARIANT="Workstation Edition"
VARIANT_ID=workstation

Code:

ls -l /var/log/ | grep audit
drwx------. 1 root  root                18 Jan 24 05:30 audit

User and others dont have any permission.
So i tried to cd using sudo

Code:

mahesh@fedora:/var/log$ sudo cd audit
mahesh@fedora:/var/log$

It is not changing the directory.

Do i have to change the file permission?

TB0ne 02-13-2024 08:33 AM

Quote:

Originally Posted by mahesh.riddles (Post 6483293)
Code:

cat /etc/os-release
Code:

NAME="Fedora Linux"
VERSION="39 (Workstation Edition)"
ID=fedora
VERSION_ID=39
VERSION_CODENAME=""
PLATFORM_ID="platform:f39"
PRETTY_NAME="Fedora Linux 39 (Workstation Edition)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:39"
DEFAULT_HOSTNAME="fedora"
HOME_URL="https://fedoraproject.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f39/system-administrators-guide/"
SUPPORT_URL="https://ask.fedoraproject.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=39
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=39
SUPPORT_END=2024-11-12
VARIANT="Workstation Edition"
VARIANT_ID=workstation

Code:

ls -l /var/log/ | grep audit
drwx------. 1 root  root                18 Jan 24 05:30 audit

User and others dont have any permission. So i tried to cd using sudo
Code:

mahesh@fedora:/var/log$ sudo cd audit
mahesh@fedora:/var/log$

It is not changing the directory. Do i have to change the file permission?

No, it's doing exactly what it should. You started a shell with elevated privileges, and the command ran successfully....upon which the sudo shell exited. Either start an interactive sudo shell with "sudo -s" and cd into that folder, or use "su - root" and run it.

mahesh.riddles 02-13-2024 10:16 AM

Quote:

Originally Posted by TB0ne (Post 6483295)
No, it's doing exactly what it should. You started a shell with elevated privileges, and the command ran successfully....upon which the sudo shell exited. Either start an interactive sudo shell with "sudo -s" and cd into that folder, or use "su - root" and run it.

Quote:

Originally Posted by TB0ne (Post 6483295)
You started a shell with elevated privileges

I never know this.
From your words, sudo cd audit => i started the shell with sudo privileges

Quote:

Originally Posted by TB0ne (Post 6483295)
and the command ran successfully....

cd audit -> it changed the directory to audit (ran the command successfully)

Quote:

Originally Posted by TB0ne (Post 6483295)
upon which the sudo shell exited.

i lost the privilege in the shell, so i came one directory up??
Or it never reached audit directory.?

mahesh.riddles 02-13-2024 10:29 AM

Quote:

Originally Posted by TB0ne (Post 6483295)
No, it's doing exactly what it should. You started a shell with elevated privileges, and the command ran successfully....upon which the sudo shell exited. Either start an interactive sudo shell with "sudo -s" and cd into that folder, or use "su - root" and run it.

i dont know the root password. I think i have not set one. Fedora did not come up with root password.
But it is awesome to know that i can change the shell with this command sudo -s

Code:

mahesh@fedora:/var/log$ sudo -s
[sudo] password for mahesh:
root@fedora:/var/log# cd audit
root@fedora:/var/log/audit#

Now it is changed to root@fedora

visudo
Code:

## Allows people in group wheel to run all commands
%wheel  ALL=(ALL)      ALL

If i change the third ALL to some specific command, then i can execute those commands only as a root. Is that right?
Code:

%wheel  ALL=(ALL)      /bin/ls, ...
How does the shell knew this? ("this (mahesh)" root is not allowed to mount, unmount, etc...)
Because my shell become root@fedora

Code:

## Allow root to run any commands anywhere
root    ALL=(ALL)      ALL


hazel 02-13-2024 10:50 AM

Be careful! Linux denies privileges to ordinary users for a good reason. It is rather easy to do something destructive when playing about as root. Yes, you can cheat by calling up a root shell, but it is always safer to use sudo. Having to prefix "sudo" to a command is psychologically useful: it reminds you that you are about to wield a potentially dangerous power and that you need to visually check the command for potential trapdoors before you press Enter.

Being a member of the wheel group does not make you root. I just tested it (I am a member of wheel on my machine and my sudoers file has the same line in it as yours does) but I still can't mount a partition that has been set as non-user-mountable or read the sudoers file. In other words I can use the commands but the result is not necessarily what I want.

Edit: I must have had a memory lapse! Of course it means that you can use sudo with any command, not just with some. It does not apply to commands used without sudo.

pan64 02-13-2024 10:58 AM

Quote:

Originally Posted by mahesh.riddles (Post 6483319)
I never know this.
From your words, sudo cd audit => i started the shell with sudo privileges

yes, but not only started a new shell, you also passed a command to execute inside (that is cd audit)
Quote:

Originally Posted by mahesh.riddles (Post 6483319)

i lost the privilege in the shell, so i came one directory up??
Or it never reached audit directory.?

No, it was successfully executed, you got no any error messages (like permission denied or similar).
But as it was mentioned your shell completed the command you specified and exited. At the end you returned back to the initial shell and also into the initial directory.

You can check it for example by executing:
Code:

sudo bash -c "cd audit; pwd; echo here; ls -l"
(or something like this)

TB0ne 02-13-2024 11:05 AM

Quote:

Originally Posted by mahesh.riddles (Post 6483326)
i dont know the root password. I think i have not set one. Fedora did not come up with root password. But it is awesome to know that i can change the shell with this command sudo -s
Code:

mahesh@fedora:/var/log$ sudo -s
[sudo] password for mahesh:
root@fedora:/var/log# cd audit
root@fedora:/var/log/audit#

Now it is changed to root@fedora

Did you read the man pages on sudo?? You need to do research on what things are and how they work.
Quote:

visudo
Code:

## Allows people in group wheel to run all commands
%wheel  ALL=(ALL)      ALL

If i change the third ALL to some specific command, then i can execute those commands only as a root. Is that right?
Code:

%wheel  ALL=(ALL)      /bin/ls, ...
How does the shell knew this? ("this (mahesh)" root is not allowed to mount, unmount, etc...)Because my shell become root@fedora
Code:

## Allow root to run any commands anywhere
root    ALL=(ALL)      ALL


Again, read up on what things do and how. If you type in "sudo -s" you get a root-equivalent shell...you are (essentially) logged in as root. If you run "sudo /some/command", it will execute that ONE COMMAND. The two aren't the same.

mahesh.riddles 02-13-2024 10:46 PM

Quote:

Originally Posted by TB0ne (Post 6483335)
Did you read the man pages on sudo?? You need to do research on what things are and how they work.

Again, read up on what things do and how. If you type in "sudo -s" you get a root-equivalent shell...you are (essentially) logged in as root. If you run "sudo /some/command", it will execute that ONE COMMAND. The two aren't the same.

Just learning linux. (last one week) That is why i am trying everything. Without trying out, it is not possible to learn i think. Just reading is not good enough. even if i broke something, it does not matter. Just using linux on old machine to learn.

I thought linux is easy to learn. It seems it is a life time learning...
Man page is really confusing me. I am not able to understand clearly what a man page is trying to explain.
So using youtube and some books.

But i am not happy. Can you please suggest me a book which can teach me the basics as well as advance concepts of linux.
Just basics is not enough.

When i try to learn about networking commands, Those are really difficult for me. It seems i need networking knowledge to understand about those commands.
Instead of man pages, Please suggest some good linux books. So i can gain some knowledge..

Thanks a lot for your help

hazel 02-13-2024 11:24 PM

Quote:

Originally Posted by mahesh.riddles (Post 6483440)
But i am not happy. Can you please suggest me a book which can teach me the basics as well as advance concepts of linux.
Just basics is not enough...Please suggest some good linux books. So i can gain some knowledge..

I learned everything I needed to know about my first Linux system by reading Running Linux. It's quite old now but I can still recommend it. Most Linux books are distro-specific but that one is not. For advice on how to understand man pages, https://www.linuxquestions.org/quest...n-pages-38130/.

pan64 02-14-2024 12:55 AM

Quote:

Originally Posted by mahesh.riddles (Post 6483440)
Just learning linux. (last one week) That is why i am trying everything. Without trying out, it is not possible to learn i think. Just reading is not good enough. even if i broke something, it does not matter. Just using linux on old machine to learn.

There is no such thing, you cannot learn linux. You can learn a lot of different things, like how does a computer work, what is a kernel or programming language, how can we connect computers, and a huge amount of other things.
Quote:

Originally Posted by mahesh.riddles (Post 6483440)
I thought linux is easy to learn. It seems it is a life time learning...
Man page is really confusing me. I am not able to understand clearly what a man page is trying to explain.
So using youtube and some books.

Again you cannot learn linux, but some parts of the system (first, and some other parts later). man pages are not really good for beginners, it is true, but youtube, books, tutorials, examples can be really useful.
Quote:

Originally Posted by mahesh.riddles (Post 6483440)
But i am not happy. Can you please suggest me a book which can teach me the basics as well as advance concepts of linux.
Just basics is not enough.

It is a life-time journey, you can decide which part is important for you or interested in. Probably others will suggest a lot of books and other resources, I would only suggest you to practice.
Quote:

Originally Posted by mahesh.riddles (Post 6483440)
When i try to learn about networking commands, Those are really difficult for me. It seems i need networking knowledge to understand about those commands.
Instead of man pages, Please suggest some good linux books. So i can gain some knowledge..

Yes, networking is a complex issue, I totally agree with you. But you can find a lot of topics about it on the net. As an example:
https://www.youtube.com/watch?v=61yMjSjgnVc

TB0ne 02-14-2024 09:07 AM

Quote:

Originally Posted by mahesh.riddles (Post 6483440)
Just learning linux. (last one week) That is why i am trying everything. Without trying out, it is not possible to learn i think. Just reading is not good enough. even if i broke something, it does not matter. Just using linux on old machine to learn.

I thought linux is easy to learn. It seems it is a life time learning...

And did you learn everything about Windows in a few minutes from reading a page or two??? Why would Linux be different??
Quote:

Man page is really confusing me. I am not able to understand clearly what a man page is trying to explain. So using youtube and some books.
The man pages for a command explain THAT COMMAND. It tells you how to use it, what it does, and what all the options are. It's a help document.
Quote:

But i am not happy. Can you please suggest me a book which can teach me the basics as well as advance concepts of linux. Just basics is not enough. When i try to learn about networking commands, Those are really difficult for me. It seems i need networking knowledge to understand about those commands.
Why would you think you wouldn't need to know network knowledge to understand what networking commands do??
Quote:

Instead of man pages, Please suggest some good linux books. So i can gain some knowledge..
You need to load Linux and actually use it. It is just not hard, and instead of thinking you're going to read a book and get good, you need to use it, just like you learned Windows right??? Load it..and if you have a problem, you then do research on how to solve it, and post here if you can't figure it out. Solve your problems one at a time...again, exactly like you did with Windows.

MadeInGermany 02-14-2024 06:26 PM

sudo runs one external command.
But a working cd must be an internal (shell builtin) command.
For some reason there is also an external cd command in many Linux distros:
Code:

type -a cd
cd is a shell builtin
cd is /bin/cd
cd is /usr/bin/cd

Code:

sudo cd /etc
runs the /bin/cd and it does not have a lasting effect.
Test it in the shell:
Code:

/bin/cd /etc
does not have a lasting effect.
Behind the scenes the shell forks/clones another shell that execs/converts to the command.
This is not necessary for an internal command.
Another internal command: set
Code:

type -a set
set is a special shell builtin

sudo does not find it because it is not an external command.
Code:

sudo set -a
sudo: set: command not found

In
Code:

sudo bash -c "cd audit; pwd; echo here; ls -l"
The sudo runs /bin/bash,
which runs the internal cd command, an internal pwd command (that could be external as well), and an external ls command.

hazel 02-15-2024 01:08 AM

Fascinating. Slackware does not include a separate cd command btw. I just checked.

pan64 02-15-2024 01:54 AM

Quote:

Originally Posted by hazel (Post 6483708)
Fascinating. Slackware does not include a separate cd command btw. I just checked.

there is no external cd command, it is just pointless. I mean not in slackware, but in general. What would it (or could it) do at all?
Open a new process, cd into somewhere and exit?

MadeInGermany 02-15-2024 03:11 AM

A discussion is here
A temporary cd can make sense because a test -d just checks the attributes.
But if you really need it then you can use a short embedded bash script:
Code:

dirs_i_am_able_to_cd_into=$(find . -type d -exec /bin/bash -c 'cd "$1"' cd.sh {} \; -print)
Same technique as for sudo.

And directly in bash you can use a sub shell:
Code:

if test -d "$dir" && (cd "$dir"); then


All times are GMT -5. The time now is 07:22 AM.