#########
Ports to remember
#########
TCP
80 http
443 https
22 ssh
20 ftp-data
21 ftp
53 domain
5901 vnc (depends on the settings of /etc/sysconfig/vncservers)
UDP
53 domain
This is my personal notes on RHCSA/RHCE exam. Site still work in progress. For comments and suggestions email me at mctofferatgmaildotcom
Showing posts with label security. Show all posts
Showing posts with label security. Show all posts
Friday, June 17, 2011
Thursday, June 16, 2011
Manage Security thru Selinux
Commands to remember
sestatus show selinux status
getenforce show enforcing status of selinux
setenforce enforcing|permissive set status of selinux
getsebool -a show the boolean value of the service
setsebool -P set the the boolean value
chcon - u(user) -r (role) -t (type) change context of a file
chcon --reference=<dir> <dir_to_change_context> copy the context of the dir as referrence
restorecon -F myfile restore file default file context
User
unconfined_u unprotected user
system_u system user
user_u normal user
Role
object_r file
system_r users processes
domain
unconfined_r unprotected file or process
Set enforcing and permissive modes for SELinux
-thru configfile edit /etc/sysconfig/selinux
-or use the command setenforce
#setenforce Enforcing|Permissive
List and identify SELinux file and process context
- File
ls -lZ
-Process
ps -eZ|grep <process name>
Restore default file contexts
restorecon -F myfile
chcon - u(user) -r (role) -t (type) change context of a file
chcon --reference=<dir> <dir_to_change_context> copy the context of the dir as referrence
Use boolean settings to modify system SELinux settings
getsebool -a show the boolean value of the service
setsebool -P <boolean>=1/0 set the the boolean value
Diagnose and address routine SELinux policy violations
To get man pages for a certain commands
man -k _selinux
Description of the boolean
semanage boolean -l #provided by the policycoreutils-python
To survive a SELinux relabel
ex: #semanage fcontext -a -s system_u -t httpd_sys_script_exec_t /var/www/cgi-bin
sestatus show selinux status
getenforce show enforcing status of selinux
setenforce enforcing|permissive set status of selinux
getsebool -a show the boolean value of the service
setsebool -P set the the boolean value
chcon - u(user) -r (role) -t (type) change context of a file
chcon --reference=<dir> <dir_to_change_context> copy the context of the dir as referrence
restorecon -F myfile restore file default file context
User
unconfined_u unprotected user
system_u system user
user_u normal user
Role
object_r file
system_r users processes
domain
unconfined_r unprotected file or process
Set enforcing and permissive modes for SELinux
-thru configfile edit /etc/sysconfig/selinux
-or use the command setenforce
#setenforce Enforcing|Permissive
List and identify SELinux file and process context
- File
ls -lZ
-Process
ps -eZ|grep <process name>
Restore default file contexts
restorecon -F myfile
chcon - u(user) -r (role) -t (type) change context of a file
chcon --reference=<dir> <dir_to_change_context> copy the context of the dir as referrence
Use boolean settings to modify system SELinux settings
getsebool -a show the boolean value of the service
setsebool -P <boolean>=1/0 set the the boolean value
Diagnose and address routine SELinux policy violations
To get man pages for a certain commands
man -k _selinux
Description of the boolean
semanage boolean -l #provided by the policycoreutils-python
To survive a SELinux relabel
ex: #semanage fcontext -a -s system_u -t httpd_sys_script_exec_t /var/www/cgi-bin
Thursday, April 21, 2011
SSH
To generate ssh private and public key
This will create under ~/.ssh id_rsa.pub public key to copied to the remote system and id_rsa private key for your local system
The best way to copy id_rsa.pub into a remote system is to use scp-copy-id This command will automatically create authorized_keys under ~/.ssh/
I tried to remove all files under ~/.ssh and the authorized_keys on the destination server. Re-do everything but when tried to ssh again, it gives me this error
One solution was to use "ssh-add" command
[chris@rhel01 .ssh]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/chris/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/chris/.ssh/id_rsa.
Your public key has been saved in /home/chris/.ssh/id_rsa.pub.
The key fingerprint is:
8c:23:99:93:4a:6d:27:9c:7b:92:07:aa:49:5d:6a:87 chris@rhel01.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| |
| o = o |
| . &.+ S |
| ..++O . |
| .oE+.o |
|.o. .+ |
|o |
+-----------------+
This will create under ~/.ssh id_rsa.pub public key to copied to the remote system and id_rsa private key for your local system
The best way to copy id_rsa.pub into a remote system is to use scp-copy-id This command will automatically create authorized_keys under ~/.ssh/
#scp-copy-id -i /home/chris/.ssh/id_rsa rhel02
The authenticity of host 'rhel02 (192.168.1.201)' can't be established.
RSA key fingerprint is 01:91:64:15:5b:64:fa:90:bb:b5:63:5e:f8:7e:73:71.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'rhel02,192.168.1.201' (RSA) to the list of known hosts.
chris@rhel02's password:
Now try logging into the machine, with "ssh 'rhel02'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
[chris@rhel01 ~]$ ssh rhel02
Last login: Fri Apr 8 03:23:42 2011 from rhel01
chris@rhel02.localdomain: ~ $
I tried to remove all files under ~/.ssh and the authorized_keys on the destination server. Re-do everything but when tried to ssh again, it gives me this error
[chris@wk ~]$ ssh rhel01
Agent admitted failure to sign using the key.
One solution was to use "ssh-add" command
[chris@wk ~]$ ssh-add
Identity added: /home/chris/.ssh/id_rsa (/home/chris/.ssh/id_rsa)
[chris@wk ~]$ ssh rhel01
Last login: Sat Jul 9 08:43:50 2011 from 192.168.122.1
[chris@rhel01 ~]$
Security quick referrence
Iptables quick referrence
iptables -t nat -A POSTROUTING -s 192.168.122.0/24 -o eth1 -j MASQUERADE
/etc/sysctl.conf
net.ipv4.ip_forward = 1
echo 1 > /proc/sys/net/ipv4/ip_forward
TCP Wrappers
How to know if daemon supports tcp wrappers
# ldd /usr/sbin/sshd|grep libwrap
/etc/hosts.allow
/etc/hosts.deny
NATCommands
iptables --line-numbers --list
iptables -[A,I,D] INPUT -p [tcp,udp] -m [tcp,udp] --dport [port-number] -j [ACCEPT,REJECT,DROP]
iptables -[A,I,D] INPUT -p [tcp,udp] -m [tcp,udp] -s ip-address/netmask --dport [port-number] -j [ACCEPT,REJECT,DROP]
iptables -t nat -A POSTROUTING -s ip-network/ipaddress/netmask -o interface-that-has-internet -j MASQUERADE
iptables -t nat -A POSTROUTING -s 192.168.122.0/24 -o eth1 -j MASQUERADE
/etc/sysctl.conf
net.ipv4.ip_forward = 1
echo 1 > /proc/sys/net/ipv4/ip_forward
TCP Wrappers
How to know if daemon supports tcp wrappers
# ldd /usr/sbin/sshd|grep libwrap
/etc/hosts.allow
sshd: 192.168.1. EXCEPT 192.168.1.202
/etc/hosts.deny
ALL: ALL
Subscribe to:
Posts (Atom)