LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-13-2024, 08:31 AM   #1
mahesh.riddles
LQ Newbie
 
Registered: Feb 2024
Posts: 8

Rep: Reputation: 1
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?
 
Old 02-13-2024, 08:33 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,641

Rep: Reputation: 7966Reputation: 7966Reputation: 7966Reputation: 7966Reputation: 7966Reputation: 7966Reputation: 7966Reputation: 7966Reputation: 7966Reputation: 7966Reputation: 7966
Quote:
Originally Posted by mahesh.riddles View Post
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.
 
1 members found this post helpful.
Old 02-13-2024, 10:16 AM   #3
mahesh.riddles
LQ Newbie
 
Registered: Feb 2024
Posts: 8

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by TB0ne View Post
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 View Post
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 View Post
and the command ran successfully....
cd audit -> it changed the directory to audit (ran the command successfully)

Quote:
Originally Posted by TB0ne View Post
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.?
 
Old 02-13-2024, 10:29 AM   #4
mahesh.riddles
LQ Newbie
 
Registered: Feb 2024
Posts: 8

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by TB0ne View Post
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
 
Old 02-13-2024, 10:50 AM   #5
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,587
Blog Entries: 19

Rep: Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455
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.

Last edited by hazel; 02-13-2024 at 11:19 AM.
 
1 members found this post helpful.
Old 02-13-2024, 10:58 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,876

Rep: Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315
Quote:
Originally Posted by mahesh.riddles View Post
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 View Post

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)
 
1 members found this post helpful.
Old 02-13-2024, 11:05 AM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,641

Rep: Reputation: 7966Reputation: 7966Reputation: 7966Reputation: 7966Reputation: 7966Reputation: 7966Reputation: 7966Reputation: 7966Reputation: 7966Reputation: 7966Reputation: 7966
Quote:
Originally Posted by mahesh.riddles View Post
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.
 
1 members found this post helpful.
Old 02-13-2024, 10:46 PM   #8
mahesh.riddles
LQ Newbie
 
Registered: Feb 2024
Posts: 8

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by TB0ne View Post
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
 
Old 02-13-2024, 11:24 PM   #9
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,587
Blog Entries: 19

Rep: Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455
Quote:
Originally Posted by mahesh.riddles View Post
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/.

Last edited by hazel; 02-14-2024 at 12:05 AM.
 
Old 02-14-2024, 12:55 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,876

Rep: Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315
Quote:
Originally Posted by mahesh.riddles View Post
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 View Post
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 View Post
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 View Post
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
 
1 members found this post helpful.
Old 02-14-2024, 09:07 AM   #11
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,641

Rep: Reputation: 7966Reputation: 7966Reputation: 7966Reputation: 7966Reputation: 7966Reputation: 7966Reputation: 7966Reputation: 7966Reputation: 7966Reputation: 7966Reputation: 7966
Quote:
Originally Posted by mahesh.riddles View Post
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.
 
Old 02-14-2024, 06:26 PM   #12
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,799

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
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.

Last edited by MadeInGermany; 02-14-2024 at 06:43 PM.
 
1 members found this post helpful.
Old 02-15-2024, 01:08 AM   #13
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,587
Blog Entries: 19

Rep: Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455
Fascinating. Slackware does not include a separate cd command btw. I just checked.
 
Old 02-15-2024, 01:54 AM   #14
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,876

Rep: Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315
Quote:
Originally Posted by hazel View Post
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?
 
Old 02-15-2024, 03:11 AM   #15
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,799

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
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

Last edited by MadeInGermany; 02-15-2024 at 03:13 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Debian 11 - audit logs in /var/log/auth.log ktpmm17 Linux - Server 9 07-04-2023 03:12 AM
How to get local timestamp msg=audit(Mon Jan 21 23:47:38 2019.689:1866319) in audit.log instead of msg=audit(1548145864.461:1866430) naveen.kumar2512 Linux - Newbie 1 01-22-2019 07:24 AM
[SOLVED] iptables troubleshooting icmp and best place to log /var/log/messages or /var/log/iptables JockVSJock Linux - Security 18 02-12-2016 12:31 AM
[SOLVED] Logrotate - what is rotating /var/log/audit/audit.log? veeruk101 Linux - Newbie 3 11-03-2011 07:53 PM
Can Samhain log my entries in /var/log/secure and /var/log/mesage to a central server abefroman Linux - Software 2 04-13-2008 04:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration