This guide walks through the process of adding a new user to a Linux system, setting up SSH access, installing Miniconda, and customizing the bash prompt.
-
Log in as root or a user with sudo privileges.
-
Create the new user without a password:
sudo adduser --disabled-password --gecos "" vladimir_albrekht
Replace
username
with the desired username. -
If the home directory already exists, adjust ownership:
sudo chown -R vladimir_albrekht:vladimir_albrekht /home/vladimir_albrekht sudo chmod 755 /home/vladimir_albrekht
-
Switch to the new user:
sudo su - vladimir_albrekht
-
Create and configure the SSH directory:
mkdir -p ~/.ssh chmod 700 ~/.ssh touch ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys
-
Add your public SSH key to
~/.ssh/authorized_keys
. -
Exit the new user's shell:
exit
-
Update your local SSH config file (
~/.ssh/config
):Host NewUserHost HostName your_server_ip User vladimir_albrekht
-
Switch to the new user:
sudo su - vladimir_albrekht
-
Download and install Miniconda:
mkdir -p ~/miniconda3 wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3 rm ~/miniconda3/miniconda.sh
-
Initialize Miniconda:
~/miniconda3/bin/conda init bash
-
Reload the bash configuration:
source ~/.bashrc
-
Open the
.bashrc
file:nano ~/.bashrc
-
Add the following code at the end of the file:
# Conda environment display in prompt conda_env() { if [ -n "$CONDA_DEFAULT_ENV" ]; then echo "($CONDA_DEFAULT_ENV) " fi } # Set the prompt PS1='$(conda_env)\[\033[01;34m\]\w\[\033[00m\]\$ '
-
Save and exit the file (Ctrl+X, then Y, then Enter).
-
Reload the bash configuration:
source ~/.bashrc
Your new prompt will now display the active conda environment (if any) and the current directory in blue, followed by a $ sign:
(base) ~/projects$
If you want to include the conda version in your prompt, replace the PS1 line in step 2 of the "Customizing the Bash Prompt" section with:
PS1='$(conda_env)(conda $(conda --version | cut -f2 -d" ")) \[\033[01;34m\]\w\[\033[00m\]\$ '
This will result in a prompt like:
(base) (conda 23.7.1) ~/projects$
Remember to source your .bashrc
file or log out and log back in for changes to take effect.
You can add custom aliases and functions to your .bashrc
file to create shortcuts for frequently used commands. Here's how to do it:
-
Open your
.bashrc
file:nano ~/.bashrc
-
Add the following lines at the end of the file:
# Custom aliases alias n='nvidia-smi' alias c='cd ..' # Custom functions function mkcd() { mkdir -p "$1" && cd "$1" }
-
Save and exit the file (Ctrl+X, then Y, then Enter).
-
Reload your
.bashrc
file:source ~/.bashrc
Now you have the following shortcuts:
- Type
n
to runnvidia-smi
- Type
c
to go up one directory (equivalent tocd ..
) - Use
mkcd directory_name
to create a new directory and immediately change into it
You can add more aliases and functions as needed. Here are some examples:
# More alias examples
alias update='sudo apt update && sudo apt upgrade'
alias ll='ls -alF'
alias py='python3'
# More function examples
function extract() {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xjf $1 ;;
*.tar.gz) tar xzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar e $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xf $1 ;;
*.tbz2) tar xjf $1 ;;
*.tgz) tar xzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "'$1' cannot be extracted via extract()" ;;
esac
else
echo "'$1' is not a valid file"
fi
}
Remember to source your .bashrc
file or log out and log back in for changes to take effect.
These customizations can significantly speed up your command-line workflow by reducing the amount of typing needed for common tasks.