Tuesday, April 1, 2014

Quick & Dirty Add User to SUDOERs (*nix)

While there is near endless and very powerful ways to configure user permissions, you've just spun up a virtual machine using VMWare or Virtual Box and you want God permissions for your user so you're not always becoming root (and then forgetting that you're root). The following example is from CentOS 6.5. Since you can destroy a system if you muck up the sudoers file just using any old text editor is not recommended. Hence, we shall use visudo.

[myuser@machine ~]$ su -
Password:
[root@machine ~]# visudo

This will open your sudoers file for editing. visudo will protect you from some, but not nearly all mistakes. So, for this quick dirty example search for the following section:
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
Then, add the following directly below it:
myuser ALL=(ALL) ALL
The end result should look like:
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
myuser ALL=(ALL) ALL
NOTE: The above is separated by TABS so you would type it as follows:
myuser[TAB]ALL=(ALL)[TAB]ALL

Save & close (:wq) 

[root@machine ~]# exit
[myuser@machine ~]$ sudo someCommand

FIN

Wednesday, March 5, 2014

Connect to SMB share with terminal - Fedora20

The non-gui way to connect to your SMB share. There is likely 1000 small variations of how to do this, but this is a very simple method to get you on to the path to bigger, better, cooler...

From a terminal:
[user@localhost user] $ cd /mnt
[user@localhost mnt] $ sudo mkdir shareExample
[user@localhost mnt] $ sudo mount -o username=user //theShareLocation/shareName /mnt/shareExample/
You will likely be prompted for your passwd...
[user@localhost mnt] $ cd /mnt/shareExample
[user@localhost shareExample] $ look around, do stuff...

NOTE: If you're accessing a SMB share on windows you will like need to connect using:
[user@localhost mnt]$ sudo mount -t smbfs -o username=username //theShareLocation/shareName /mnt/shareExample/

...and when you're done:
[user@localhost mnt]$ sudo umount /mnt/shareExample

This should work on all flavors of *nix, done here on Fedora20 as that is what I'm using at the moment.

FIN

Wednesday, January 16, 2013

Generate SHA hash - OSX

I'll have to clean this post up later, but just to get this down.  Pulled the new Fedora 18 XFCE spin from the torrent and needed to verify it with the provided SHA256 hash.

At it's most basic:
computer:directory user$ shasum <filename>
<some_hash> <filename>
In the case below I needed a SHA256 hash so the -a arg was necessary:


computer:directory user$ shasum -a256 <filename>
<some_256_hash> <filename>


So, here is what I did - some content removed for brevity(...):

berlin:tmp bkarels$ cat Fedora-18-x86_64-Spins-CHECKSUM
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
...
95a75c...29dd6e *Fedora-18-x86_64-Live-XFCE.iso
berlin:tmp bkarels$ shasum -a256 Fedora-18-x86_64-Live-XFCE.iso
95a75c...29dd6e  Fedora-18-x86_64-Live-XFCE.iso
Checking the hash against a provided list was not as clear from the man pages.  In brief you need to use the output of a shasum as input to shasum -c.  Here you need only find 'OK' vs. relying on your human ability to visually compare hashes on a terminal.

Basic:
computer:directory user$ shasum -a 256 <filename> | shasum -c <CHECKSUM_FILE>
blah blah blah output: OK
Example:
berlin:tmp bkarels$ shasum -a 256 Fedora-18-x86_64-Live-XFCE.iso | shasum -c Fedora-18-x86_64-Spins-CHECKSUM
...
shasum: Fedora-18-x86_64-Live-Scientific-KDE.iso: No such file or directory
Fedora-18-x86_64-Live-Scientific-KDE.iso: FAILED open or read
shasum: Fedora-18-x86_64-Live-Security.iso: No such file or directory
Fedora-18-x86_64-Live-Security.iso: FAILED open or read
shasum: Fedora-18-x86_64-Live-SoaS.iso: No such file or directory
Fedora-18-x86_64-Live-SoaS.iso: FAILED open or read
Fedora-18-x86_64-Live-XFCE.iso: OKshasum: WARNING: 7 of 8 listed files could not be read
Fin.

NOTE: For clarity, here is the entire contents of the example file Fedora-18-x86_64-Spins-CHECKSUM:


berlin:tmp bkarels$ cat Fedora-18-x86_64-Spins-CHECKSUM
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
3684ae2814c7e54b4f66f0411a385846533e40f107d7fff4e331c2f547951ec2 *Fedora-18-x86_64-Live-Design-suite.iso
b11da64d527e333e2160cbf5fde49f89205f932d48fa7c01690232fc1b0cacfa *Fedora-18-x86_64-Live-Electronic-Lab.iso
ea34f626488623a1f84b2041df9c65468357bfdb878f034392da16f6c9d05264 *Fedora-18-x86_64-Live-LXDE.iso
8700aa64a6485e338b3d9aa419ecadc0c87884c77203a35c6e1847147a4dca06 *Fedora-18-x86_64-Live-Robotics.iso
3bb90d115daf6f0d2279cd5a669fb265c090cb6e88125424ae960a980f9ba50d *Fedora-18-x86_64-Live-Scientific-KDE.iso
7802a1c024f9471fba90724f53c0d95045acd76c3c4346b467cb53f5608248a9 *Fedora-18-x86_64-Live-Security.iso
736e8dd36de4207fe899648299abb6b3220fd1d1bcb48b8bf712d01d2ec02bf5 *Fedora-18-x86_64-Live-SoaS.iso
95a75c334ce82b33f1a5d81eab196600e40c7933fd5f7bfa8e6ed9534529dd6e *Fedora-18-x86_64-Live-XFCE.iso
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
iQIcBAEBCAAGBQJQ8FZnAAoJEP8BElzefzi9BdUQALd1dlX39NVq/GWuoR7iCrxo
+ZS5gFzp5ObdPp2+MFdKszMEI7HQnkv5Xvj7qTrUS41LwrLSAX7BN5wiuzYbD0wv
f10U7K907inViXWUbANCx/fqVDLXtC/lkRYMh0JEOyRP6VYCOjcTzby+pxfOhG3u
naAtUApx/WbydwOheyT1GJCV8e15/oXqYxDoJmQuAX7AliDyysVdtcsgDP9GEiJ+
jApOywZHdxVYzUJQlXkoYEAn9LzeOh69MEL8wP30GHGI4GBo0CMUouhXlvcnoNyj
Ov9Px/8xFSSQ6vs7rapayyaue4vCxa13Y79KKQzh+/f0G2KXgInW59Y70Q0lYkLS
SCYwNUxACSlguetDfzqTtXTAFbYUcHTcc6YLuCQGRUZbDNev/dq5pnIMLSQiDnKq
YXQd1a8qH0ZpRQCMHhRwYq6satKz1ui0PgRpAn4ScPdye8Fda9+tC5VI07SDEduX
lDvzgNgOIWA3dMgSPkcaW/jcanAB3ubgPxiyAitU12TzEPwE8RuMFlYhoIczr5pu
g1aQrw/kOng6OJGjlJWd5Sb3Qabsm3OW3hfJ7wER9TRWdDT2zwo3A+j6hYsE5og+
oLbVJhQFyqpIr9o5rhtoU3bVIyOqjl5WY+4PlTrQ+1gt1qjrY9Z0tzoSGk3ESaMi
txw7WyBRjomA/D+4jzMR
=/hTc
-----END PGP SIGNATURE-----





Thursday, June 21, 2012

Set tabstop in VI - Mac OSX


From within VI

(Assuming you would like to use four spaces for your tabs)
:set tabstop=4

To make this behaviour the default:

user@machine:~$ cd ~
(if ~/.exrc does not exist, create it.  Otherwise skip to next cmd.)
user@machine:~$ touch .exrc
user@machiner:~$ vi .exrc

Add the following line to the file:
set tabstop=4


Save and close .exrc

user@machine:~$ . .exrc
user@machine:~$ vi someTextFile.txt

Basically, if the file .exrc does not exist in your home directory create it.
Open .exrc for editing.
Add the line (w/o quotes) "set tabstop=4"
Save .exrc
Source .exrc
Test to verify function.

This should also work in most flavors of *nix.

~Fin

Wednesday, May 25, 2011

mkdir and cd to created directory with a single command - 11.04 Natty

Not a fan of having to cd to the directory you just created? You likely created it for a reason and 8 times out of 10 not need to cd to it immediately anyway. So, you do this:
user@machine:~$ mkdir -p /dir/needed/to/cd/to/immediately
user@machine:~$ cd /dir/needed/to/cd/to/immediately
user@machine:~$ pwd
/home/user/dir/needed/to/cd/to/immediately

Quick functional solution: Open ~/.bashrc (or .bash_profile) and add the following line:

function mkdircd () { mkdir -p "$@" && eval cd "\"\$$#\""; }

NOTE: You can name this function whatever you like, mkdircd just makes sense to me...

Source ~/.bashrc and now let's do this the easy way:

user@machine:~$ mkdircd dir/needed/to/go/to/immediately
user@machine:~/dir/needed/to/go/to/immediately$ pwd
/home/user/dir/needed/to/go/to/immediately

~Fin

Thursday, April 14, 2011

OS X::10.6 - configure: error: C compiler cannot create executables

Ran into this trying to compile Apache Httpd:


Configuring Apache Portable Runtime Utility library...

checking for APR-util... yes
checking for gcc... gcc
checking for C compiler default output file name...
configure: error: in `/Users/bkarels/devtools/httpd-2.2.17':
configure: error: C compiler cannot create executables
See `config.log' for more details.


Mac OS X solution:

Go back to: Snow Leopard DVD > Optional Installs > Xcode.mpkg:

Option: System Tools > Checked
Option: UNIX Dev Support > Checked <-- Important

Run installer. No reboot necessary. Compiler commands execute as expected.

Credit to solution author kevinx.
Original thread from discussions.apple.com: can be found here.

Monday, April 11, 2011

"Remote" administration of Linux VirtualBox® Guest Virtual Machines

Sometimes you just need a sandbox of your very own. Oracle's VirtualBox has long offered a way to let you play with a guest OS on your host system - but what if you need to interact with the guest from your host? In my case I wanted to simulate a sharded MongoDB cluster that, to be a true simulation, required a minimum of three servers.

Here we will go over the process of setting up your virtual machine in such a way that you can "remote" administer it and connect to it like any server on your network. For this example I will be running and OS X host with a Ubuntu Server 10.10 guest.

1. Download and install Oracle VirtualBox® here.

2. With VirtualBox® installed, let's take a look at our network settings on the host machine with `ifconfig`. Here you will want to take note of the vboxnet0 address:



3. Add a new virtual machine using the Oracle VM VirtualBox Manager. Once the initial setup is complete select the new virtual machine can click on the network adapter to add a second:



4. Adapter #1 will be configured by default and does not need to be altered. Click on the tab for `Adapter 2`, enable, and configure as follows:



5. Click the green arrow in the VM Manger to start the new virtual machine and install the new guest. (the rest of this example assumes a guest of type Ubuntu Server 10.10 but should be very similar for all flavors of *nix.)

6. During the guest install be sure to select eth0 as the primary network adapter.



7. Also, to save the need to set up the OpenSSH Server later, you can elect to do so as part of the OS install.



8. Start up the new guest and login.

9. Configure eth1 by modifying /etc/network/interfaces Add the following lines:
(NOTE: The address below is made up from the VBoxnet0 address noted in Step 2 above. Since mine defaulted to 192.168.56.1 I was free to use any value beyond that as below.)

# Secondary network interface for VBox0
auto eth1
iface eth1 inet static
address 192.168.56.102
netmask 255.255.255.0

10. Save and close /etc/network/interfaces and bring up eth1 using:
sudo ifup eth1


Your terminal might look like this when done:



11. Open a terminal on your host machine and connect to your guest using SSH:



If all went well you should be connected via SSH to your guest system and be able to interact with it as you would any server on your network. So, let's fire up a remote MongoDB server on our guest and verify that we can reach the Http Interface for the instance.

Starting up mongod on port 27000 on mongo2 (Http Interface defaults to [port] + 1000 or 28000 in this case):



...and voilĂ ! We are connected to our "remote" instance.



Fin