Friday, April 17, 2015

How To Add User To Sudoer File Without A password


I want to have a user have sudo access without needing a password, so I did this.


sudo vi /etc/sudoers

Set this up:

# Members of the admin group may gain root privileges
%admin  ALL=(ALL) NOPASSWD:ALL
sudo service sudo restart
sudo adduser  sudo

How To Add A New SSH Key To A Ubuntu Server


HOW TO ADD AN SSH KEY LIKE A DUMMY:

So if you have a client machine and you want to give them access to your server do this.
ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/client/.ssh/id_rsa): /Users/client/.ssh/new_key
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/client/.ssh/new_key.
Your public key has been saved in /Users/client/.ssh/new_key.pub.

This generates two files:
/Users/client/.ssh/new_key        (private)
/Users/client/.ssh/new_key.pub (public)
Now you must copy the public key to the server of interest. On the server after you have copied the local file you can append to the 
cat /home/john/new_key.pub >> /home/john/.ssh/authorized_keys
Now the user can login using their private key.
ssh -i /Users/client/.ssh/new_key john@myserver.com

Monday, February 23, 2015

Stupid Simple Keep Alive Bash Script

Everyone has servers and processes they want to keep alive and if they are not alive they want to restart them. But they don't want the restarts to get out of control.

This is a stupid simple bash example that will allow you to do that. I'm using it to restart a python notebook.
#!/bin/bash
#This silly script was written by @bentaylordata to handle auto restarting of processes in cron

#Check if string is running
string_of_interest="ipython"
OUTPUT="$(ps -ef | grep $string_of_interest | wc -l)"

if [ "$OUTPUT" -gt "1" ]
then
        echo "started"
else
        echo "need to start"
        ipython notebook --profile=nbserver --no-mathjax &   #This backgrounds the notebook server
fi