So you found the magic sauce did ya? So you created a user with useradd or adduser and you try to switch over to that user in a terminal, probably logged in through ssh as root right.
You are trying to use the su – username command but all you get is a $. And not the good kind. The kind that no matter what you type all you get is another line with $ on it. This is a feature by the way so you can’t see files that don’t belong to the user…
Right now you are probably like
As far as I can tell, if you are using Debian or Ubuntu, useradd/adduser defaults the users shell to /bin/sh but the skeleton files located in /etc/skel are all configured for bash. I have no idea how the system gets the defaults, but it does no good to have your users default shell not pointing to bash.
How to fix this?
To fix it you need to change the users default shell to bash. Bash is usually located in /bin/bash or /usr/bin/bash For me it was /bin/bash. To change it you use usermod command like so
usermod -s /bin/bash username
That will change the shell your user gets when you type su – username. Now since Ubuntu/Debian and maybe other distros contain the configuration in the users .bashrc and .profile files everything will work as expected. When you switch to the user with the above command you are taken to their home directory.
-s, –shellSHELLThe name of the user’s login shell. The default is to leave this field blank, which causes the system to select the default login shell specified by the SHELL variable in /etc/default/useradd, or an empty string by default.
So that is where Linux gets the default value for the user shell and apparently you can use the -s option when creating the user to specify the bash as the shell.
Digging deeper into the mystery sauce I find in my Mastering Ubuntu Server book ( awesome book ) the reason why. It states if you use adduser then their default shell is /bin/bash and if you use useradd (which I used) it defaults to /bin/sh
SSL is a very important subject. All websites/apps should be using it. However the docs will leave you scratching your head saying WTF? So I am creating this long list of resources for anyone else who ever has to learn how to use it.
First here is a link to the docs – this will cause confusion as nothing tells you how to use the pieces together. So it is like looking into a box of legos and knowing it builds something but you don’t even have a picture as a hint. The best you can do is use the pieces to build something that doesn’t even resemble the original creation.
I am writing this so when other people google how to do it, they have something to find to save them time.
For days I tried to figure out how to make sure a command finished before another was run. I couldn’t find any information anywhere. If you are like me you may be thinking ( or wondering if ) that the shell just zooms through the commands you put in a script file without waiting for each to finish. It seems like this because everything is rushing by so quickly you can’t read it.
For days I was running scripts to install and configure my servers and it kept hanging so bad I couldn’t even ping the server.
I was running the following for example
sudo apt-get update
sudo apt-get dist-upgrade -y
sudo apt-get reboot
And since my server instances were hard freezing right up, I figured it must be zooming right on through causing an error.
Well come to find out after much research and someone on twitter finally confirmed to me that the shell automatically waits for each command to finish before executing the next. The shell doesn’t automatically run all commands encountered at the same time.
Now I must figure out what is actually locking my server instances up.
I saw something similar to this in some code in one of my books var=$[ $var1 - $var2 ]
I wanted to know what it did and why it was used. I’m a perfectionist with OCD.
Turns out it is deprecated from the BASH language.
Originally $ was used to do math in Bash scripts to do Math known as arithmetic expansion.
So the new way in BASH is to use the following syntax.
var=$(( $var1 - $var2))
Basically what this syntax does is it allows you to do math more easily. Without the above syntax you have to escape certain characters like >< With the above syntax you can basically do math without escaping plus youcan use post-increment $var++, post-decrement $var– , logical and &&, logical or || bitwise math etc. It really helps you out.
Another good source of info about the (()) syntax as used in if and while statements is found in the book Linux Command Line and Shell Scripting Bible. starting on page 325 If you don’t own the book I highly suggest it. I’ve found one errata so far and that is what this post is about.
While trying to figure out how to do this I found lots of bad info, info that lead to nothing but issues and bugs. I have stay so busy and do so many things I can never remember how to do anything. That is basically why this ENTIRE blog exists, my shit memory.