Categories
Resources Software Development Web Security

Stupid linux issues.

This is my collection of stupid.

Top of the list Debian/Ubuntu removes apt-key support and doesn’t tell anyone they did it, doesn’t give anyone a single hint as to what to do. No just remove/deprecate shit and don’t tell a single soul on earth. This kind of stupid makes me want to leave the industry entirely. I get so tired of messed up  and undocumented shit that wastes hours and hours and hours of my time. Someone needs kicked for this.

More info and links about the above issue or removing apt-key support. Yarn suggests using apt-key so this means hundreds of millions of people are having this issue or will or could.
Even more info about the stupid ideas from above.

Categories
Resources Web Development

Linux su command not working, does nothing but show $ prompt

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

Wait. WTF is even happening?

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.

Found more details!

More info

Ok I found more info while digging into the so called useradd docs.

-s–shell SHELLThe 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

Links

how to change the default shell of an user in linux? – more info about usermod and changing the users default shell and how to figure out what shells you have installed and their locations.

Categories
Resources Software Development Web Development Web Security

SSL links, videos and other resources.

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.

Articles

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.

OpenSSL quick reference by digicert – a very brief introduction to SSL and how it works

SSL Certificate Security Glossary – list of terms and definitions

How to create a CSR with openssl – shows some of the syntax for the -config file option.

Docs explaining the config file found in the article above bout how to create a csr with openssl

SSL Basics: What is a Certificate Signing Request (CSR)? – Exactly WTF is a CSR

Openssl config file example – openssl docs are pure 100% utter shit. I had to dig and dig and google and dig for days to find this.


Videos

Categories
Resources Software Development

How to make linux shell scripts wait for a command to finish before running another

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.

now you know
Categories
Resources Software Development

What does a dollar sign followed by a square bracket $[…] mean in bash?

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.

Further links, resources and information

More info on stackexchange Same as the link above

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.

More links and resources to BASH scripting

More links and linux resources

Categories
Resources Software Development

Debian Ubuntu Linux debconf resources and information

The debconf programmers tutorial – excellent tutorial on what debconf is and how to use it.

debconf documentation

Using debconf to configure a system – article about using debconf, gives a little more explanation of what it is.

Installing MySQL with debconf – good article

Categories
Resources Software Development

Ansible resources links videos and information

Ansible is used to provision/setup servers for your app.
Why is Ansible better than shell scripting?

Categories
Resources Software Development

Mysql resources links and information

This page contains links and videos to information about MySQL database.

More on MySQL option files in the documentation here.

Categories
Random Resources Software Development

How to push an existing project to a Github repository

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.

I found this article on DigitalOcean that works properly.

Step 1 create a repository on Github, even if the code you want to put in a repo exists, as long as it is not currently in any repo at all.

Step 2 navigate to the folder that contains the code that you want to push to the new Git/Github repo and run git init

Step 3 add the files with git add -A or git add .

Step 4 commit the files

Step 5 add the remote git origin server

Step 6 push to the remote git origin server

Or just use this script.

 

Categories
Resources Software Development

Linux commands resources and links

Difference between Ubuntu apt-get autoclean, clean, autoremove commands – it is important to know the difference.

Cleaning up with apt-get – how to clean up with apt clean command

How To Upgrade Ubuntu Using Command Line?

Linux << heredoc syntax info – great link has lots of good linux information

Here is an excellent link to a shell command cheatsheet. This lists the most commonly used shell programs.

An A-Z Index of the Linux command line: bash + utilities. – about the same as the list of shell commands above.20 Shell Scripting Questions for Practice

Writing text to files from shell or shell scripts

Awesome linux software – a list/article about awesome useful linux programs
Understanding Shell Initialization Files and User Profiles in Linux

20 Shell Scripting Questions for Practiceuses opensshLinux visudo command

Linux /etc/profile file information

Understanding a little more about /etc/profile and /etc/bashrc20 Shell Scripting Questions for Practice

Why and How to Edit Your Sudoers File in Linux

LINUX DIRECTORY STRUCTURE:/ETC EXPLAINED

Tutorialspoint Linux tutorials and really good information.20 Shell Scripting Questions for Practice

How to Use Sudo and the Sudoers File – very good article

Ubuntu Environmental variables – Ubuntu Documentation link

How to prompt for input from user in a linux shell script – article 20 Shell Scripting Questions for Practicecovers two ways to prompt users for input in shell scripts.

How to prompt and read user input in a Bash shell script – A good example of a script that prompts users for input and uses it.

Bash read builtin command – this command is built into bash meaning available without installing etc.

Linux while loop explained with examples of alternate syntaxes

How to create a self signed SSL certificate 

20 Shell Scripting Questions for Practice – article showing how to prompt users for input and how to answer prompts.