function f-tutorial.7 () { bold ; cyan clear echo ; echo echo "In Which We Become Powerful and Dangerous." white cat << EOPOWERSTART This tutorial gets a bit schoolmasterly - only because I've seen people get burnt. We have briefly met the "sudo" command already. A bit of background is in order... There is a certain amount of controversy about this command - most of it ill informed. Traditionally, GNU/Linux has by default used "su" as the command to gain administrative rights. The administrative user is known as "root", since that user has control over all files in the system from "/" down. Originally "/" was the root user's "home" by default - the whole filesystem was effectively "home" for the Godlike "root" user. The waters have been muddied, because most systems now have a dedicated /root directory, which is a sensible idea, since even root needs some privacy and somewhere to put files without spraying them all over the system ;-) Actually, the "su" command does not, contrary to what some people believe, stand for "Super User" ;-) "su" actually means "switch user". It simply defaults to switching to the root user, unless another user is specified. Now, "sudo" can do similar things, but it was originally used to give fine-grained control over which users were authorised to run what commands, or access which parts of the system. As you have probably guessed by now, we are about to tell you how to become a sorcerer's apprentice. Do, please, remember what happened to the apprentice in the story... The lecture is not quite over. We do move on to some useful information eventually ;-) EOPOWERSTART f-tutescape echo echo ; bold ; cyan echo "Using sudo without tears." white ; echo cat << EOSUDOINTRO INX is based on Ubuntu, which has removed the scary lectures that were standard fare for new users. One of the traditional ones popped up when "sudo" was first invoked: "We trust you have received the usual lecture from the local System Administrator. It usually boils down to these two things: #1) Respect the privacy of others. #2) Think before you type." ... seemingly irrelevant for users on home systems, or single-user systems - but the point is still worth making. EOSUDOINTRO bold ; cyan ; echo echo "\"Thou Art Mortal.\"" white cat << EOLECTURE In Rome, a slave was assigned to stand behind the hero of conquest in his chariot, as he passed through the streets in triumphal parade, acknowledging the plaudits of the crowd. The slave was told to whisper in the conqueror's ear: "Thou art mortal." I suggest that you whisper the same thing to yourself each time you become a sudo (pseudo?) deity on your system. ;-) If you don't, your mortality will become only too clear soon enough! EOLECTURE f-tutescape echo echo ; cyan ; bold echo "\"Permission denied...\"" white cat << EOPERMISSION This sort of thing is unfamiliar to users of certain operating systems that shall remain nameless. "It's my system! What do you mean, 'permission denied'? I'll do as I like!" ...and so on. Get used to it. Permissions are your friends. There are excellent reasons for them, and changing them should be done only with careful thought. There are several commands used for permission setting. The common ones are: EOPERMISSION echo ; bold ; yellow echo "chmod" echo echo "chown" white ; echo echo "The first one changes the \"mode\" of files and directories. The \"mode\" is a set" echo "of symbols or numbers. For example if we type" echo ; yellow echo "ls -l /usr/bin/mplayer" echo ; white echo "we see" echo ls -l /usr/bin/mplayer cat < tags.)" f-tutescape echo ; bold ; cyan echo "By the Numbers." echo ; white echo "You'll recall I ranted about \"777\" permissions. In simplified form, the numbers" echo "look like this:" echo ; cyan echo " User Group Others" echo echo "Read 4 4 4 " echo echo "Write 2 2 2 " echo echo "Execute 1 1 1 " echo " ________________________________________________________ " echo echo " 7 7 7 " echo ; white echo echo "Thus, adding or subtracting numbers, we see for instance that \"644\"" echo "means \"User/Owner can read and write, Group can read, Others can read\"" echo echo "755 means Owner/User can do anything, group can read and execute, and so can others." echo echo "And so on... So you can see how 777 permissions undermine security - in fact, a lot" echo "of things will simply stop working, completely, if such permissions are applied." echo echo "So, suppose we add the smart user \"Roid\" to the \"elite\" group..." echo echo "Read on..." f-tutescape echo ; cyan ; bold echo "User Roid's Rise and Fall." echo ; white echo "Roid has been admitted to the Holy of Holies - the \"elite\" group!" echo "/home/inx/elite has permissions 070 and ownership inx:elite. That looks like this:" echo ; yellow ; bold echo "$ ls -ld elite" echo "d---rwx--- 2 inx elite 60 2007-10-31 07:14 elite" echo ; white echo "Remember this is an example... Hey, the elite directory is EXCLUSIVE!" echo "Let's see what happens to Roid..." echo ; unbold echo "tty6:roid@inx:/home/inx$ cd elite" echo "tty6:roid@inx:/home/inx/elite$ " echo ; green ; bold printf "Woohoo!" ; magenta ; printf " Roid is so..." ; green ; printf " IN!" echo ; white echo echo "Sadly though, it turns out Roid doesn't quite measure up to the Elite profile..." echo ; yellow ; bold echo "tty1:inx@inx:~$ sudo deluser roid elite" echo "Removing user 'roid' from group 'elite' ..." echo "Done." echo echo ; white ; unbold echo "tty6:roid@inx:/home/inx$ cd elite" echo "bash: cd: elite: Permission denied" echo "tty6:roid@inx:/home/inx$" echo ; magenta ; bold echo " :'(" echo ; white echo "So long, Roid. Thanks for your interest... Have a nice day..." echo echo "Don't slam the door on the way out." echo ; cyan echo "On that note, we end tutorial 7... :-) " f-tutescape f-tutorial }