useful Linux stuff

This is a collection of useful Linux commands and procedures that I compiled as a reference for me since I always forget this stuff.¬†Hopefully it will prove to be useful for others too ūüôā

 

 

Creating a bootable USB installation key

http://www.ubuntu.com/download/desktop/create-a-usb-stick-on-mac-osx

 

Resetting root password

http://linuxconfig.org/recover-a-forgotten-root-password-on-redhat-7-linux-selinux-system

It’s happened to me before, and this page was useful in quickly resetting the root password from the console.

  1. press ‘e’ at boot menu
  2. find and ¬†replace ‘rhgb quiet’ with ‘init=/bin/bash’
  3. press ‘ctrl+x’
  4. # mount | grep root
  5. # mount -o remount,rw /
  6. # mount | grep root
  7. # passwd
  8. # touch /.autorelabel
  9. # exec /sbin/init

Networking

Hostname

hostnamectl status
hostnamectl set-hostname node.domain
hostnamectl set-hostname "pretty name" --pretty
hostnamectl set-chassis server
hostnamectl set-icon-name computer-server

 

Static IP

/etc/sysconfig/network-scripts/ifcfg-enp0s3

BOOTPROTO=static
IPADDR=x.x.x.x
NETMASK=255.255.255.0
GATEWAY=x.x.x.x
DNS1=8.8.8.8
DNS2=8.8.4.4
NM_CONTROLLED=no
...
PEERDNS=no
...
ONBOOT=yes

/etc/resolv.conf

nameserver 8.8.8.8
nameserver 8.8.4.4

restart the network interface with:

/etc/init.d/network restart

 

hosts file

/etc/hosts

255.255.255.255 name.domain alias

 

ssh without password

Generate keys and copy to hosts:

ssh-keygen
ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host-name

On a Mac without ssh-copy-id, I used this command for copying keys:

cat ~/.ssh/id_rsa.pub | ssh user@remote-host-name 'umask 0077; mkdir -p .ssh; cat >> .ssh/authorized_keys && echo "Key copied"'

 

Installing Java

sudo yum install java-1.7.0-openjdk-devel

 

setting up a user with sudo

 

setting up NTP

yum install ntp ntpdate ntp-doc
chkconfig ntpd on
ntpdate pool.ntp.org
chkconfig ntpd on
service ntpd start

Setting Up “NTP (Network Time Protocol) Server” in RHEL/CentOS 7

 

Install openssl

yum upgrade openssl

rpm -qa | grep openssl

openssl-1.0.1e-16.el6.x86_64

 

 

disable firewalld

systemctl status firewalld

systemctl disable firewalld

 

 

install httpd

yum clean all

yum -y update

yum -y install httpd

systemctl enable httpd

systemctl start httpd

systemctl status httpd

 

apachectl start

apachectl stop

apachectl restart

apachectl status

 

disable SELinux

vi /etc/sysconfig/selinux

SELINUX=disabled

 

https://wiki.centos.org/HowTos/Https