Category Archives: Commands

Auto Added by WPeMatico

WHO DID WHAT WITH ROOT?!

When you are not sure who is using SUDO on a server, and you really need to know who keeps making that annoying change.  You can install something to watch them, and maintain that software and related logs. Keep it setup in your package management system, and make sure it doesn’t have any patches.

OR

You could use the little-known (at least those I have asked in the field) modifications I will list below.  They are two fold.  One, you will enable to record who logs in and uses SUDO, and records their session. Much like many pieces of software out there today.  The one catch to my method is simple.  You already have the software installed, yup this has been a feature of SUDO since version 1.7.4p4.  So nothing else to install, worry about, or maintain.  It is also very easy to setup, see below:


/etc/sudoers modifcation:
All you need to do is to add 2 tags to all required sudoers entries.
*(where "su" specified, either with command or alias). 
LOG_INPUT and LOG_OUTPUT
Example: 
%admins ALL=(ALL) NOPASSWD: LOG_INPUT: LOG_OUTPUT: ALL

It will add the following default log dir structure to sudoers: Defaults iolog_dir=/var/log/sudo-io/%{user}
Note:
Output is logged to the directory specified by the iolog_dir option (/var/log/sudo-io by default) using a unique session ID that is included in the normal sudo log line, prefixed with TSID=.  The iolog_file option may be used to control the format of the session ID.  Output logs may be viewed with the
sudoreplay(8) utility, which can also be used to list or search the available logs.   Keeping in mind that if the user has a really long session you will be viewing it like a movie, it will replay as if he is sitting there typing.  With this in mind, sudoreplay gives you the ability to play back at faster speeds.  This makes it easier to find where things happened in a long recording.

So that is one good method to help find a culprit, but what if you are just looking at history of root?  Can you tell me who ran what? Can you tell me when they ran the commands you see when you type ‘history’?  By default, no.  The next tidbit of info is very useful, and extremely easy to add to your machines.  Simply add the following to your /etc/profile:

export HISTTIMEFORMAT="%m.%d.%y %T "

Yes, that is a space at the end.  If you do not put that in there you will end up with it running together with the actual command typed in history.  So your history should look like the example below:

1995 06.10.15 13:08:05 top
1996 06.10.15 13:08:05 clear
1997 06.10.15 13:08:05 df -h
1998 06.10.15 13:08:05 umount /media
1999 06.10.15 13:08:05 sudo umount /media
2000 06.10.15 13:08:05 sudo su –
2001 06.10.15 13:08:07 history

I hope this helps someone save some time, as it has me.  Please feel free to share with others.

-M

 

How to use a PS1 in Linux/MAC

Here are the PS1‘s I use for my daily driver.  Feel free to take them and change them up.

I use different colors, so one doesn’t accidentally login or run something as root (which is in red, users are yellow).

To use these, simply copy and paste them into either the root user; or regular user’s .bashrc.

Alternatively you can add them to /etc/profile to make them enforced system wide. 

For MAC, it is the same; however the PS1 is a little different. See below.

 

Root

 

User

Handy One-Liners – Full Debian Update

This one is great for a “Full Update” on debian / ubuntu machines.

It calls the script without ever installing anything (assuming curl is installed).  Be sure to run as root, either with sudo or as root directly.

As you can see in the snippet; it uses a script that is remotely hosted (in a github gist).  This is great because you  can see exactly what it does by looking at the script.  It just calls system commands, so it can’t do anything malicious.  Just run sudo, then the above command and it will run the below script:

Another trick you can do with something like this, is copy it to  /usr/bin/fullupdate (as root of course), and ensure its executable “sudo chmod +x /usr/bin/fullupdate”.  Then you can call “sudo fullupdate”, from anywhere and use it when needed. Alternatively, you can use it on a cron to run on a schedule!  If you don’t want all the options, just download the script and change it for your liking.

 

Welcome to open source.

Don’t forget! Linux Learning Resources

This is kept under the Linux Learning Project and Learning Resources section of the site, and is updated occasionally with new links.  Feel free to suggest one by contacting me directly.


LEARNING RESOURCES

Help/Chat:

Resources:

The Eagle Has landed….

All,

I have made it…. the move is complete!   I just wanted to say thank you for everyone that has been waiting on me.  I know I have taken a while on a few things, and I am finally in a position to run with everything again.  I finally have a decent internet connection [330mbps/330mbps]; so I will also be able to host things at high speed for us now as well.

As far as the installer goes, I hope to be done very soon with it ;  I am putting my final touches on it for the Pixel desktop.  If I get time I might be able to get Bluetooth working!  However, I have to get caught up first.

For those waiting on hardware, most has been shipped with a few exceptions.  I have notified those people.  I have a true ‘shop’ area again, and this will allow me to be much more efficient.  Meaning shorter wait times/etc…

 

Sincerely,

-M

A few BASH tips from an old Linux admin.

Everyone has seen these “Top 50 commands” blah blah blah….. #clickbait….

I am writing this just to make BASH a much more pleasant experience for people new and old to Linux.  It is also for any sysadmin that has simply not been introduced to some of them.

I could list tons of them, but that’s going to get a simple TL;DR for most people.  Then they will move on.  So I will list a few and lets let those digest.  Keep in mind all commands are in Linux, and may vary by distribution.

First BASH tips (Simple, but time savers):

  1.  Type ‘cd’ and you will go to your home directory for the user you are logged into.
    1. Similar to “cd” ~, however ~ can sometimes rely on the environment.
  2. To return to the previous directory you can type ” cd -“.
    1. This will return you to your previous location, not home.
  3. Type “tailf”, instead of “tail f” for the same results.
    1. Also, “tail -200” can be used instead of “tail -n 200”
  4. Use a custom “PS1” for root, and regular users.
    1. A “PS1” is the text in the login prompt. See Example to the right:
      1. Notice it is yellow
      2. Do the same but in red for root.
    2. Examples:
      1. Debian PS1 for a normal user (as seen to the right)
      2. Debian PS1 for a ROOT user.
        1. These will need to be added to the bottom of “.bashrc” in your home directory
        2. Keep in mind files starting with a . are hidden in Linux, but there.
          1. I also have MAC PS1’s public in my gists.

 

I think that is enough for today, I hope this helps make BASH your friend.

 

-M

NEW Jasper Documentation!

Hello All,

First, I want to thank everyone that has been patient with me so far in getting these things done one at a time…

I know it is not easy to get some of these things completed without good documentation.  So, with the help of a few community members, I have started what is a very rough draft of our documentation.  It is neither complete, or ready….  However, we are adding information as we go, so keep a close eye.  Even feel free to clone it, and contribute.  There will be documentation on how to do both of those coming as well.  Feel free to watch here, the repository, or the Support Forums/Slack for updates.  I update them all.

If you have items you would like to see added to the documentation, I would run it by myself, or d34dman first.  If we have not already written it (there are some not committed yet); then we will just let you know to put in a PR (aka Pull Request).  Once we have both reviewed it and give it a thumbs up.  We will merge it.

Alright, all that said… Here is the link to the documentation!

 

Thanks,

Matthew Curry

Jasper Image v1.5 Released

Major Updates

NOTE:  Be sure to do a “git pull” in the “Jasper-RPI-Tools” directory to get the updated scripts.

  • Installed Home-Assistant.io
    • Script to enable Home-Assistant.io Daemon
      • It is located /home/pi/Jasper-RPI-Tools/enable-hass-service.sh
    • Config under /home/hass/.homeassistant
    • Installed in Virtual Environment
    • Installed under the “hass” user.
  • Removed clutter from rc.local
    • Was causing harmless error at boot.
  • Installed needed dependencies for the development branch
    • libmad0 * libmad0-dev
  • Created/Enabled Service for jasper “jasper-daemon”
  • Created/Disable Service for Home-Assistant.io (user needs to enable)
  • Created Script to download a specified version of Jasper/Jasper-dev
    • It is located /home/pi/Jasper-RPI-Tools/installers/jasper-repo-installer.sh
      • You can pick what branch you would like to use at clone-time
  • Ensure phonetisaurus pre-compiled/installed
  • Removed Erroneous cron entries
  • Updated the OS and all related pkgs

Jasper Client Links

These are several links I have compiled, and/or created in the last few months. They can help you get Jasper going. I am also working on a full how-to for both RPI2 and RPI3.

  • Jasper-Support-Forums
    • Support forums, I help run these if you have any questions. Contact Me.
  • SLACK SIGN UP
    • Chat room for helping with Jasper
  • Jasper-Client
    • Official Jasper-Client
  • Jasper-RPI-Tools:
    • Set of tools I created in helping setup Jasper/RPI. They are a work in progress, so be sure to do a ‘git pull’ often.
  • RPI-Jasper-Dependencies:
    • Set of pre-compiled dependencies, that would normally take hours to compile. Tested on RPI2/3. Usually used for a non-Jasper image; as the images I created have them all installed.
  • ALSA Setup Wiki
    • Help with ‘.asoundrc’, and setting your default audio device
    • Usually the most common road block.
  • Home-Assistant.io: Home automation for the RPI, works very well. Working on integration on the same RPI; however it has dependency conflicts. Testing in pyenv soon…
  • How TO: Burning SD Card