Month: September 2024

  • Customize Your VIM Settings

    Customize Your VIM Settings

    Introduction

    VIM is a popular Linux text editor program. Users can customize VIM by creating a .vimrc file in their home directory. Then, when launching VIM, it will load any variables that were preset in this file. You’ll need to set the file permissions of the .vimrc file to rw-rw—-.

    A sample .vimrc file

    In my opinion, the two most useful commands are to set line numbers on the file and set the color scheme, to make files easier to read. Here is how you set them up in the .vimrc file.

    Get a list of available color schemes

    VIM comes with several color schemes loaded by default. You can also download others. To check what defaults are available, use this command.

    References

    https://phoenixnap.com/kb/vim-color-schemes

    https://thelinuxcode.com/vimrc_tutorial

  • File, Processes, & System Details in Ubuntu

    File, Processes, & System Details in Ubuntu

    Introduction

    When working with systems, for troubleshooting, performance tuning, or regular maintenance, it’s often essential to gather key system information. This includes details such as the operating system version, hardware specifications, running processes, or file system disk usage. You might need to monitor CPU usage in real time or check how much storage space is available on your drives.

    Fortunately, there are a set of powerful command-line tools that make this process quick and efficient. Below, we’ll explore some of the most useful commands to help you monitor and manage your system effectively.

    What is OS Linux version

    Get the installed memory (RAM)

    Get a CPU count

    Get the hard drive details

    Get disk space usage by directory

    disk space used by the specified files and for each subdirectory.

    Monitor Processes using TOP

    Just run the command ‘top’ or ‘htop’ , if it is installed, to get real time Mem and CPU usage and see what process are resource hogs.

  • Change Windows Cmd Line Startup Folder

    Change Windows Cmd Line Startup Folder

    Change Default Startup Path for Command Prompt

    Right click on the command prompt then select properties. On shortcut tab, change “Start in:”

  • Start Encrypting Your Files in Windows

    Start Encrypting Your Files in Windows

    Getting Started

    File encryption adds a level of security to your critical files. In Windows, you can create an encrypted folder and it will auto encrypt any files you drop into the folder.

    Windows uses the Encrypted File System (EFS) platform. The first time you encrypt a file, it will auto generates a key set and a certificate. Windows manages the encryption for you on the backend. In other words, once you set it all up, it will automatically decrypt a file when you open it, and encrypt it when you close the file.

    After you set up a folder in windows and encrypt it, any files you drop into that folder will automatically be encrypted too. No need to set the encryption on each file.

    Check to see if your files are already encrypted.

    Does the folder or file has a lock on it?

    An alternate method, is to go to the file, right click, select details, check the attributes for the E flag. (Note: The A flag means the archive bit is set).

    Finally, you can open a command prompt and run cipher.

    Here are two folders, one has encrypted files inside it and one does not.

    Encrypt a folder or files

    The easiest way to encrypt multiple files is to create an encrypted folder and drop files into it. Make a new folder on the desktop, right click on folder, select properties, go to general tab, select advanced button, and check the encrypt box.

    After you see the lock icon on the folder, this means the folder is encrypted. Any files you drop into it, will automatically be encrypted too and will display the lock icon. If you drag the the file outside the folder, it will remain encrypted.

    Note: the lock symbol does not always show up right away after you encrypt a file/folder, don’t panic.

  • Understanding User Crontabs

    Understanding User Crontabs

    Introduction

    Crontab stand for CRON table and it is the primary task scheduler for Linux. The CRON daemon runs every minute and checks each user’s crontab (and the system crontab) for scheduled jobs. CRON will auto start on reboot and record to syslog natively when a job runs. CRON will send “standard out” and “errors” to the scheduled user’s mail account at /var/spool/mail/user. By default, CRON uses the bash shell to execute commands.

    There are two types of crontabs; user crontabs and system crontabs. The system wide CRONTAB jobs are stored in /etc/crontab. It is used to execute scripts that apply to the system change or all users. It requires an additional field in the crontab called a user field. This article will be focused on setting up a user’s crontab.

    If your script runs successfully from the command line, but not when it is run as a CRONTAB job, it is because crontabs are executed by the user CRON. That user has limited rights and does not have the same environmental variables as a regular user. It is recommended to always use absolute paths for shell, commands, and scripts, in your crontab.

    Understanding crontab

    Key Terms:

    • Min = 0 to 59
    • Hour = 0 to 23 (Hours are in Military time)
    • Day of Month = 1 to 31
    • Month = 1 to 12 or Jan, Feb, Mar
    • Day of Week = 0 to 6 (0 is Sunday) or mon, tue, wed
    • @reboot = run once after reboot

    Pattern Matching:

    • * = match everything
    • Range = 0-4 or jan-jun
    • List = 1,3,7,16 or mon,tue,wed
    • Step Values = 0-23/2 = run the job every two hours for 24 hours.

    File Locations:

    • System file =/etc/crontab
    • System jobs = /etc/cron.d/ (Location to store system scripts)
    • System jobs = /etc/cron.daily (Location to store system scripts)
    • System jobs = /etc/cron.weekly (Location to store system scripts)
    • System jobs = /etc/cron.hourly (Location to store system scripts)
    • User’s crontab (debian) = /var/spool/cron/crontabs/<user>. (DO NOT EDIT DIRECTLY)

    Troubleshooting:

    • Crontab Logs = /var/log/syslog (logs, i.e. did command run??)
    • Crontab Job Results (debian) = /var/spool/mail/<user> (output and errors)
    • Verify cron is running = sudo systemctl status cron (Is cron running ??)

    List the current user’s crontab

    Edit current user’s crontab

    NOTE: Some documents say, after you save and install a new CRONTAB, you need to reload the CRON service by running “service cron reload”. But, other documents say you do not to perform this action.

    Remove current user’s crontab

    List another user’s crontab

    Run a job at a specified time

    NOTE: CRON uses military time, which is using hours 0 to 23.

    Potential syntax errors

    Be careful when writing cron jobs. For the day of week and day of month fields, crontab should be interpreted as AND statements. The command will run when either field matches the current time! This example would not run a script on the first Monday of the month. Rather, this job runs on the first day of the month and every Monday.

    Skip values can only operate within the time period they´re attached to. The above will not execute every 35 minutes. Rather, it will execute at 0 minutes and 35 minutes each hour.

    Start a program on server reboot

    “/usr/bin/perl -w” mean to enable and print warning messages.

    Run a script and email the results

    Send stdout&err to syslog w tag “ossec”

    Redirect screen & error output

    Screen output and errors are recorded in the user’s mailbox at /var/spool/mail/<user>. When scripts run overnight, output to the screen (stdout) is not needed. It is common to send standard out to /dev/null and errors to a custom log file. You will need to ensure that the log file does not grow out of control.

    2>&1 means to send any errors to the same location as standard out. Order matters! you can not send errors to location that does not exist. Be sure to identify the location of the screen output first.

    References

    https://krisjordan.com/blog/2013/11/04/timesaving-crontab-tips

    https://www.generateit.net/cron-job/