středa 16. dubna 2014

system-wide $PATH change (CentOS)

Thanks to this source.

create /etc/profile.d/custompath.sh with:

pathmunge () {
        eval dOPATH="\$${1}"
        if ! echo ${dOPATH} | /bin/egrep -q "(^|:)$2($|:)" ; then
           if [ "$3" = "after" ] ; then
              export ${1}=${dOPATH}:$2
           else
              export ${1}=$2:${dOPATH}
           fi
        fi
}
if [ "$LOGNAME" != "root" ]
then
  pathmunge PATH . # for those who like it
  pathmunge PATH /usr/local/texlive/2013/bin/x86_64-linux append
fi

remarks
  • custompath.sh does not need to be executable
  • definice of pathmunge has to be present, it does not propagate from /etc/profile

sobota 5. dubna 2014

CentOS + Apache + Self signed ssl certificate

Various guides are available, e.g. a short one or an official HowTo.

#Generate private key 
openssl genrsa -out ca.key 2048 

# Generate CSR 
openssl req -new -key ca.key -out ca.csr

# Generate Self Signed Key
openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt

# Copy the files to the correct locations
cp ca.crt /etc/pki/tls/certs
cp ca.key /etc/pki/tls/private/ca.key
cp ca.csr /etc/pki/tls/private/ca.csr

Original version: this creates CA certificate (?)

yum install mod_ssl
 
mkdir -p /etc/httpd/ssl/ && cd /etc/httpd/ssl/
 
openssl req -x509 -nodes -days $((20*365)) -newkey rsa:2048 -keyout /etc/httpd/ssl/server.key -out /etc/httpd/ssl/server.crt

Generating a 2048 bit RSA private key
..........................................+++
...........................................................+++
writing new private key to '/etc/httpd/ssl/server.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:xx
State or Province Name (full name) []:City
Locality Name (eg, city) [Default City]:City
Organization Name (eg, company) [Default Company Ltd]:XYZ, Ltd.
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:domain.name.org
Email Address []:my@emajl.com
The most important is to specify "Common name" as the fully qualified hostname (resovable by DNS), or, at least, IP address.
then add to:

vim /etc/httpd/conf.d/ssl.conf

SSLCertificateFile /etc/httpd/ssl/server.crt
SSLCertificateKeyFile /etc/httpd/ssl/server.key
To make SELinux happy, restore context:

restorecon -RvF /etc/httpd/ssl

Finally,

service httpd restart

and check your success:  
https://www.ssllabs.com/ssltest/

pátek 4. dubna 2014

Centos autofs - automatic mount of samba share

A very useful feature.

yum install autofs

vim /etc/auto.master
the only active (uncommented line) should be:
/mnt/auto /etc/auto.samba --timeout=600 --ghost

create new file:
vim /etc/auto.samba
ID -fstype=cifs,username=USR,password=PSW,uid=NAME,gid=users ://server.xy/share

target mount will be:
/mnt/auto/ID

non-standard SSL port for apache (on CentOs) and owncloud

The procedure is not limited to owncloud installation, of course.

Install SElinux tools:

# yum install setools-gui setroubleshoot checkpolicy

check available (i.e. already allowed) http port

# semanage port -l | grep http

http_port_t          tcp   80, 81, 443, 488, 8008, 8009, 8443, 9000

For custom ports, see RedHat docs. In short, the  correct command for port 12345 is

# semanage port -a -t http_port_t -p tcp 12345

then change port in conf.d/ssl.conf, or add a "virtual host: for owncoud:

vim /etc/httpd/conf.d/owncloud.conf:
 <Directory /var/www/html/owncloud>
  AllowOverride All
</Directory>

Listen 12345
and include the Virtual host part from the ssl.conf
<VirtualHost *:12345>
DocumentRoot "/var/www/html/owncloud"

ErrorLog logs/ssl_oc_error_log
TransferLog logs/ssl_oc_access_log
LogLevel warn

SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM
SSLCertificateFile /etc/pki/tls/certs/ca.crt
SSLCertificateKeyFile /etc/pki/tls/private/ca.key
CustomLog logs/ssl_oc_request_log \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>              

pátek 21. února 2014

migrace "spisovky" mezi pocitaci

1. dostatecne vybaveny server:  php moduly...
Oficialni pozadavky:


2. kopie adresare na druhy stroj
[root@novy ~]# cd /srv/www/htdocs/
rsync -avP -e ssh stary:/srv/www/htdocs/spisovka33 .
chown -R apache. spisovka33/client spisovka33/log # writable adresare
ln -s spisovka33 spisovka

3a. kopie databaze - komplet
stroj1:
root@stary:/home/user/spisovka> mysqldump -p --all-databases > db_backup.sql

stroj2:
[root@novy ~]# scp -C user@stary:spisovka/db_backup.sql .
[root@novy ~]# mysql <db_backup.sql 
[root@novy ~]# mysql
mysql> use spisovka33 ;
mysql> flush privileges;
mysql> GRANT ALL PRIVILEGES ON spisovka33.* TO 'spisovka'@'localhost' ;
mysql>\q

3b. kopie pouze databaze spisovky
stroj1:
root@stary:/home/user/spisovka> mysqldump -u spisovka -p spisovka33 > db_backup.sql

stroj2:
[root@novy ~]# scp -C user@stary:spisovka/db_backup.sql .
[root@novy ~]# mysql
mysql> create database spisovka33 ;
mysql> use spisovka33 ;
mysql> flush privileges;
mysql> CREATE USER 'spisovka'@'localhost' IDENTIFIED BY 'XXXXXXX';
mysql> GRANT ALL PRIVILEGES ON spisovka33.* TO 'spisovka'@'localhost' ;
mysql>\q
[root@novy ~]# mysql -u spisovka -p spisovka33 <db_backup.sql  

sobota 8. února 2014

ssh tunnel over NAT or firewall (chained ssh)

Your target server is running e.g. vncserver on port 5904. Your gateway has a free port 6111. Your client has a free port 333

client:~> ssh -A -t  user1@gateway -L 3333:localhost:6111 \
ssh -A user2@target -L 6111:localhost:5904


Then:

client:~> vncviewer ::3333

pondělí 3. února 2014

Reset image orientation and other EXIF tricks

Different image viewers/editors use different EXIF tags to set image rotation, so the best way is to avoid use any of them. IMHO physical rotation (preferably lossless) is the best solution. So, how to get rid of any rotation for all x-thousand holiday photos?

I have found two suspicious exif tags: Orientation and Rotation. Wipe them off from my pictures

exiftool  -Orientation=  -Rotation= -overwrite_original_in_place .

(the final dot stands for the current directory)
Or:

for i in *JPG ; do
   exiftool  -Orientation=  -Rotation= -overwrite_original_in_place "$i"
done

---------------
To delete the relatively large preview image (created by the Lumix camera for its own display) try:
exiftool -P -overwrite_original -PreviewImage=  -trailer:all= *jpg

---------------
Copy all tags from other files (original files)

for i in * ; do 
    exiftool -tagsfromfile src/$i -iptc:all -codedcharacterset=utf8 \
             -overwrite_original $i ; 
done