Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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
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
and the command ran successfully....
cd audit -> it changed the directory to audit (ran the command successfully)
Quote:
Originally Posted by TB0ne
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.?
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
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.
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
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.
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.
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..
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/.
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
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
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
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
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.
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.
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?
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:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.