In today’s article, and for no apparent reason, we’re going to learn how to disallow directory listing in the terminal. This seems like a good article for beginners to learn, and it seems like something most folks might like to know. So, if you want to disallow directory listing read on!
You never know when you might want some additional privacy, though I’d definitely not confuse this for strong privacy measures like encryption, amongst your files. Perhaps you’re planning on releasing a memo and you don’t want anyone to read it until you’re done?
I dunno? It’s up to you as to why you’d want the potential privacy from making it so that the files in a directory can’t be listed. Your reasons are your own. I just share tidbits of knowledge.
We will be using ‘chmod’ in this exercise. The man page for ‘chmod’ describes itself like:
chmod – change file mode bits
But, for our purposes and generally speaking, it’s used to adjust the file permissions. As you should know, files have various permissions in Linux – and everything in Linux is a file. There are read, write, and executable bits that can be set (with said chmod, for example) and there’s also file ownership (for another day). We’ll be using those permissions to prevent listing the files in a directory.
Ready? It really won’t take long – and it should be easy enough for anyone…
Disallow Directory Listing:
As the title suggests, this is another ‘in the terminal’ application. So, of course, you’ll need an open terminal. You should open a terminal now. If you don’t know how to open the terminal, you can do so with your keyboard – just press
With your terminal now open, let’s first start by making a directory – just so that we can then use that to disallow directory listing. We’ll just do this in your /home directory. Start with:
Now, let’s move to the new ‘sample’ directory and make a couple of files.
touch foo.txt bar.txt
Now, what we’re going to do is change the permissions of the ‘sample’ directory, like so:
chmod 0111 ~/sample
You don’t need ‘sudo’ or anything, because these files belong to you. But, you can now test it. While still in the folder, try any of the following:
Or (from outside the directory, if you’d like):
In all cases, it should give you a ‘permission denied’ error, because you no longer have permission to list files from within that directory.
If you wish to reverse this, you can simply try changing the permissions again. You can just:
chmod 0666 ~/sample
With that command, you can resume directory listing. So, it’s pretty easy to reverse the process. It’s also not the greatest security measure you can take, because of that. So, do what you will with it, as you now know how to disallow directory listing in the terminal.
There you have it, it’s yet another article. This one seemed like an interesting one to write, so I figured I’d write it. You never know when you want to disallow directory listing, but now you know how to do so. If you have any questions, feel free to ask…
Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.
2 thoughts on “Disallow Directory Listing (in the terminal)”
Hi i am Pete. 57 yo not working, because of sickness for a few years now
This was my very first linux experience. thank you for that.
But i have a “guest” a very unwanted visitor rebuilding my macbook and try fishing my money.
he calls himself “var” and i think he/she is german (a guess) i have no idea how to kick him out and not come back! (a littlte light in this, is that i have learned a lot, trying to fight them of. i am alone and had no interest in life for a long time. which is probably why i write all this blablabla now. sorry! but this hacker started something in me, a reason to get out of bed every day, both pissed off but also with a little excited about what i will face today. maybe he is just a Bot* or something but i want to fight it-he-she as much as possible.I want to get rid of them, get my mac back, and i want to learn as much of this (i’m lit, feels good) trying to take him down, lol. I don’t even know if i do a difference.. i am very new but have fought the intruder. since the end of septemper. i have learned something new every day since. I am sorry for all this writing and hope you don’t get tired until you read a questioni have for you. i did the ‘chmon’ and everything did as you wrote. i just copied and i still feel like a pro. 😉 my question is if you have an idea how to do something that will give him a surprise kick in his balls.. and i lean something too..? i really hope i don’t step on any toes here, if this is a mistake, pls let me know and i will delete and sneak away like a fat ninja.
If the intruder is that involved in the system, your best option is a nice clean installation – with strong passwords and serious considerations to which software you add atop your newly installed operating system.
If they’re that far into your system, there’s no ‘cleaning’ and ‘closing’ that I’d trust. You have no idea how many back doors they’ll have added, for example.