nisham22
10/5/2017 - 9:47 AM

Ubuntu

Ssh key generation

ssh-keygen -t rsa

To add authorized users

mkdir .ssh
sudo chmod 700 .ssh
vim authorized_keys
  - place the ssh pub key of machine
sudo chmod 0600 authorized_keys

To create a sudo user in ubuntu

https://www.digitalocean.com/community/tutorials/how-to-create-a-sudo-user-on-ubuntu-quickstart

Git Color

parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '

fi

Start and End a Service

sudo service <service name> start
sudo service <service name> stop

File Permission

sudo chown root:root /etc/postfix/sasl/sasl_passwd /etc/postfix/sasl/sasl_passwd.db
sudo chmod 0600 /etc/postfix/sasl/sasl_passwd /etc/postfix/sasl/sasl_passwd.db

Port Opening using IP-tables

sudo iptables -I INPUT -p tcp --dport 3000 -jACCEPT

Root Privelage

sudo su

Process status with pid

ps aux | grep <process name>
ps -ef | grep <process name>

Kill a process

kill -9 <process name>

IP-Local

ifconfig

Run a process at background with nohup (eg : python process)

nohup python <fine_name.py> &
tail -f nohup.out

Without appending to nohup.out (eg : java maven )

nohup java -jar target/<filename>.jar >/dev/null 2>&1 &

SSH to remote system using pem file

ssh <username>@<ip-address> -i <example.pem>

SCP file from remote to local system

scp -i <pem file> <username>@<ip-address>:<source/file/path> <destination/file/path>

Chmod file permissions

chmod 777 -R <directory/filename>
chmod +x <filename>

Get all running process with corresponding port

sudo netstat -ntpl