-
What is the difference between
.bashrc
and.bash_profile
?Solutions
The difference concerns the difference between a “login shell” and a “non-login shell”. A shell is a login shell the first time you log in (i.e., when you first
ssh
). You can create non-login shells by running thebash
command from an existing shell.With that background, we can now appreciate the difference between the two files.
.bash_profile
gets run when you start a *login shell.bashrc
gets run when you start a non-login shell
For most people, you don’t care about the difference so a common procedure is to have all of your configuration in your
.bashrc
andsource ~/.bashrc
from your.bash_profile
. -
Say I have a python script (you can run a python script as a bash command by doing
python script.py
).- a) I want to be able to run it as a command from any directory, what do I need to do to accomplish this?
- b) Now I want it to run every time I login to Attu, how would I do this??
Solutions
- a)
alias randomnumber="python script.py"
(note you would likely want to use an absolute path to make sure you can run it from any directory) - b) Add it to your
.bashrc
-
How could I make it so if I type
attu
in a shell on my local machine it will ssh into attu?Solutions
alias attu="ssh username@attu.cs.washington.edu"
-
How could I print all the files in my current directory that belong to the
cse391
group?Solutions
The first solution works generally, but fails in some minor edge cases such as a file named
cse391
. The second solution works more generally:ls -l | grep "cse391" find . -group cse391
-
I have the file
run.sh
, it currently has unknown permissions. Say I want the owner to have read, write, and execute permissions, the group to have only execute permissions, and others to have only execute and read permissions.- a) How can I accomplish this using letter codes?
- b) What is an equivalent command using octal syntax?
Solutions
- a)
chmod u+rwx,g+x,g-rw,o+rx,o-w run.sh
- b)
chmod 715 run.sh
-
Suppose I want to run a web server that includes some secret files. I plan to create a dedicated Linux user
webserver
to run this program. Is this enough to ensure that the secret files are “safe”?Solutions
Likely you’ll need to also ensure that the permissions are set correctly on those secret files to prevent other people on the system from reading/writing/executing them (e.g. 600 permissions). A good example of this are the keys stored in your
.ssh
directory. Notice how no one but the owner can read them! Note: in general, it’s a bad idea to store secrets in plaintext files unless absolutely necessary. -
How bad would it be if someone hacked into your attu/vergil/etc account? What about if someone hacked into a CSE support staff account? What kind of things related to users/groups/permissions would you want to consider when assessing the “risk” associated with a particular account being hacked?
Solutions
While it wouldn’t be great if someone hacked into your attu/vergil/etc account, they likely would be limited in what harm they could do on a server. This is because most user accounts are fairly restricted on the servers. In contrast, if they hacked into a CSE support staff account, they would likely have permissions to do much more damaging and malicious things.
What groups a user belongs to and the permissions associated with those groups (as well as if the user has sudo access) are useful things to consider when assessing the “risk” (though you’d probably consider a lot more in a full risk analysis). For example, your instructor belongs to a group allowing them to edit the 391 website. If someone hacked your instructor’s account, they could insert malicious code into the course website!