What the following does: download source code, unpack it, make directory ~/.localpython to install into, run the configuration file setting install going to install folder, compile, install compilation, create a virtualenv pointing to the install, switch to the virtualenv to use it:
Note the venv folder stores neither the Python installation nor your code for your project. It is only used to store version information about the Python installation used for your project.
virtualenv instead of venv
I ran into a not-so-obscure reason to use virtualenv instead of venv. If you ever want to serve a Flask app using Apache or some other production server, virtualenv creates a file called activate_this, which Apache can use to run the Flask app in the appropriate Python environment.
getent group or getent group | grep searchsomething
To get the status, including rules being enforced, of the uncomplicated firewall:
sudo ufw status
To list all processes currently running;
ps aux | grep searchsomething
To find a particular file or directory from among all files:
sudo find / -name "searchsomething"
or for directory name search only:
sudo find / -type d -name "searchsomething"
To search for specific text within the files within the current directory:
grep -nr 'searchsomething*'
To show all ports being listened to:
ss -tuln
$ is the normal prompt for commands
# is the system administrator prompt
in the C shell, the prompt ends with %
> is used to send the output to a text file. >> is used to append the output to an existing text file without over-writing.
$VARIABLE_NAME is a variable
apt combines apt-get and apt-cache and it is newer. Use apt.
sudo apt update && sudo apt upgrade -y
To install Python packages, use apt only if you want to install directly on the machine, otherwise use pip. Pip installs modules slower, but installs the latest versions, and most importantly works within a virtualenv. In the special case of Raspberry Pi, use apt because it knows the unique processor architecture and installs the correct builds of modules.
script savedcommands.txt
A .sh file is an executable shell script. # to comment within
./ is used to specify the current working directory especially when running something that could be the same as a system command.
nano is the basic user-friendly text editor.
To view $PATH, echo "${PATH//:/$'\n'}" or just echo $PATH
To edit $PATH for the current session, export PATH='/new/directory:$PATH'
> sends command output to a file. >> appends the output to a file without overwriting existing contents.
ls -al shows all files in directory including hidden
whatis is a brief explanation
man gives a manual
less is like cat, but one page at a time
Useful Linux Commands
At this point, you are using Linux. Either Raspberry Pi OS or Ubuntu are “flavors” of Linux. Having a list of basic commands is helpful:
This step appears complex and does not appear necessary especially this early in the process. Strictly speaking, it is indeed not necessary. You could skip this step and do everything as the root or default user that already exists. However, it is best to do this now because:
to do things in the right order
to highlight an important aspect of the Linux OS: that Linux is very user-specific and permissions-based. This makes Linux less intuitive at first but makes it secure enough to be accessed by many different anonymous people as a server without allowing hackers to access sensitive parts of the server.
to avoid inevitable frustration later. Using Linux you will see “permission denied” errors periodically throughout your experience and you are better off expecting and troubleshooting them than believing that Linux is just annoying. Permissions are built-in to Linux from the ground up and it’s best to work with it rather than try to ignore it.
Logging in as a non-root user is safer. For example, some installations of Ubuntu default to external root login disabled, which means for a remote server you would be locked out if this were set and you don’t have another user to login as.
sudo adduser new_username
usermod -aG sudo new_username
Change the password for the current user as desired with:
passwd
Grant all privileges to the user with the command
sudo visudo
and add a line in the /etc/sudoers file below the root user line: new_username ALL=(ALL:ALL)ALL
This only allows the user to give itself privileges. The user does not have all read/write privileges like the root itself. Log in as the new user through SSH.