Gilles.is

/Today/20210120-Vandaag-20-January-2021

Toggle Light


By Gilles Trenson
this is a 2 minutes read
32 paragraphs

Vandaag 20 January 2021

Kali linux on Raspberry Pi - Part 2

#kali#kalisetup#zsh#cmd

Enable zsh as a default shell

The default shell is configured during the creation of the user account. It's configuration is stored in the /etc/passwd file. As a reminder, the directory etc stores editable system configuration files. I try to remember the e of etc as editable.

Where is zsh located?

The first question which arises: "Where is zsh located?". Let's find out, enter which zsh --> /usr/bin/zsh or enter cat /etc/shells to have an overview of all available shells --> /bin/zsh. At two locations, but are they refering to the same data block? The only way we can be sure, is to compare their inode number, the unique id that is assigned to each file. The inode can be retrieved using ls. Sure they are!

ls --inode /bin/zsh /usr/bin/zsh

Reconfigure the default shell

Next step is to adjust the /etc/passwd so our current user (kali in my case) uses zsh as a default.

cat /etc/passwd | grep kali # Find out which shell we're using right now
sudo sed -rie 's/^(.*):.*/\1:\/bin\/zsh/i' /etc/passwd 0> /dev/null
# -r = extended regex; -i = change in place; -e = what follows is an expression
# stdout ('standard output') is redirected to /dev/null OR you could use -n of `sed` as well

On reboot, you'll see a Z Shell configuration function for new users promp. Choose the settings of the system administrator to get started. A file called ~/.zshrc is created in your home directory which containes the necessary settings.

Install Oh-my-zsh

Zsh is easy to extend and cofigure using Oh-my-zsh. This is a no-brainer. We need this.

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
rm .zshrc.pre-oh-my-zsh # Remove the old configuration file ohmyzsh saved

We'll install the theme pure, our preferable zshtheme. In the .zshrc

#totd

rc in .zshrc stands for run commands and is used to identify files which contain startup information about a command.

sed -i 's/ZSH_THEME=.*/ZSH_THEME=""/' ~/.zshrc
git clone https://github.com/sindresorhus/pure.git "$ZSH_CUSTOM/plugins/pure" # Install pure
git clone https://github.com/zsh-users/zsh-autosuggestions "$ZSH_CUSTOM/plugins/zsh-autosuggestions" # Install autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting "$ZSH_CUSTOM/plugins/zsh-syntax-highlighting" # Install syntax highlighting
git clone https://github.com/supercrabtree/k "$ZSH_CUSTOM/plugins/k" # Install k - an alternative directory listing

And add the plugins in your .zshrc file

sed -rie 's/plugins=\((.*?)\)/plugins=(\1 pure zsh-autosuggestions zsh-syntax-highlighting k)/' ~/.zshrc
cat .zshrc | grep plugins= # just to do a quick check
source ~/.zshrc # Run the configuration file again to adapt the new settings

A lot of plugins are installed out of the box, including git, pip, python, postgres,... You can have a look using ls $ZSH/plugins. To enable them, add them to your .zshrc. Previously we used a predefined sed command to add them, but you can use vim as well.

Some more options are available to change the default shell (see reference) but I advise you to get used to the default tools like sed.

Configure git server

In the past I figured out how to build a git server. It's not that complicated. It involves creating a new user with restricted rights. Repositories are just folder inside the home folder (which is the git folder for the user git). A bare repois initialised inside the folder and is added as a remote to the user.

This idea has been explored in an earlier post - [[

#Git

]]. However, now I want to take the time to fully explore the process and to use only the bare essentials.

Step 1 - Create a new user

The first step involves the creation of a new user. I forgot which command I needed to create a new user so I did a quick search using apropos. What it does is it searches through all man (manual) pages for the keyword you're looking for.

apropos "create.* user" # Search for this keyword

This results in 5 responses. One of them is useradd, this will be the one I guess. However, the first sentence in the description of the man page stages (man useradd):

useradd is a low level utility for adding users. On Debian, administrators should usually use adduser(8) instead.

So I need to use adduser... Ok --> man adduser

In general, there are 5 ways to use adduser:

  1. Configure a new user
  2. Configure a new system user
  3. Configure a new user group
  4. Configure a new system group
  5. Add existing user to existing group

We'll make a new system user since we're not using this as an account.

sudo adduser --system \ # Create a system user
--shell /bin/zsh \
--uid 9000 \ # Specify a unique user id - can be ommited
--gecos 'Git Server' \ # Define the name of the account
--group \ # Place new user in group with same id as the user itself
--disabled-password \ # No login is possible using a pw, only ssh-keys
--home /home/git \ # The home directory
git # The name of the user

To login into the account, use sudo su - git. It's a passwordless account. We'll need a .ssh folder to store the known_hosts and our ssh-key which will be generated by the ssh-agent. To check if it's up and running, check the status of your daemons --> run sudo systemctl status. Doesn't look like our ssh-agent is running.