/

Random stuff that might be useful

Written by Johan Söderberg on 2017-02-07

Certificate

List information in a certificate

openssl x509 -text -in server.crt

List information in a request

openssl req -text -noout -in server.csr

Create a certificate that doesn't require a password (add -des3 to require password)

openssl genrsa -out server.key 4096

Create csr

openssl req -new -key server.key -out server.csr

Sign (self signed)

openssl x509 -req -days 720 -in server.csr -signkey server.key -out server.crt

List info for a remote cert

openssl s_client -showcerts -connect www.domain.com:443

Gentoo

Related to updating

emerge -uav --deep --newuse world
emerge -uav --deep --newuse --with-bdeps=y @world
revdep-rebuild -- --ask

Remove unused packages

emerge -a --depclean

Other stuff

perl-cleaner --all
python-updater -p
equery belongs /path/to/file

List USE flags for a package

equery uses xscreensaver

Re-emerge your universe:

emerge -a --emptytree system
emerge -a --emptytree world

List preserved libs, these are old libs that remain because some package use them. We don't want any.

portageq list_preserved_libs /

Update the packages that are causing preserved libs

emerge -a @preserved-rebuild

Get a tree view of dependencies and see what is really pulling in which package

emerge -pvuDNt @world

Ubuntu

Updating

apt-get update
apt-get upgrade

Remove unused kernels

uname -a
dpkg --list | grep linux-image 
apt purge <kernel image>

UTF8

SSH to a server that uses iso8859-1

luit -encoding "ISO 8859-1" ssh <server>

irssi

screen -U -S irc

/set term_charset UTF-8
/set recode_autodetect_utf8 ON
/set recode_fallback UTF-8
/set recode ON
/set recode_out_default_charset UTF-8
/set recode_transliterate ON
/recode add SERVER_NAME ISO-8859-1

Git

Create a repository

proj=FOO

mkdir /var/git/$proj
cd /var/git/$proj
git init --bare --shared=group

chgrp -R users /var/git/$proj

cd ~/work/src
git clone /var/git/$proj

git add <filename>
git commit -a
git push origin master

CVS to git

cvs co <CVS NAME>
cd <CVS NAME>

git cvsimport -C <OUTPUT PATH>

mkdir /var/git/<CVS NAME>
cd /var/git/<CVS NAME>
git init --bare --shared=group
chgrp -R users .

cd <OUTPUT PATH>
git remote add origin /var/git/<CVS NAME>
git push origin --all

Virtual (virsh/qemu/kvm)

Create image

qemu-img create -f qcow2 my_image.img 10G

Local ssh tunnel

ssh -L 5901:localhost:5901 server

Connect using vncviewer

vncviewer localhost:1

Other

Mount using cifs

mount -t cifs -o \
'username=johan,workgroup=WORK,iocharset=iso8859-1,uid=johan,
gid=users,password=censur,file_mode=0660,dir_mode=0770' \
//10.1.1.5/Share /mnt/data

List content in a view (mssql) http://msdn.microsoft.com/en-us/library/ms176112.aspx

sp_helptext

Mysql

One row for each INSERT

mysqldump --extended-insert=FALSE

Reset password

/usr/bin/mysqld_safe --skip-grant-tables

mysql> use mysql;
mysql> update user set Password=PASSWORD('NEW') WHERE User='root';
mysql> flush privileges;

Check MyISAM tables (won't modify or do anything)

myisamchk --silent *.MYI

Fix the tables. Shutdown MySQL first

myisamchk --silent --force --update-state *.MYI

Purge binary logs

PURGE BINARY LOGS TO 'mysqld-bin.000404';

Show character encoding

SHOW VARIABLES LIKE 'char%';
SHOW VARIABLES LIKE 'collation%';

Convert a database from iso8859-1 to utf8

Dump database to dump.sql and then convert to utf8 using

iconv -f iso8859-1 -t utf8 dump.sql > dump_utf8.sql

Change in dump_utf8.sql

*!40101 SET NAMES utf8 */;

For tables (in dump_utf8.sql)

) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Create the database

SET NAMES 'utf8';
CREATE DATABASE MyDB_utf8 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT COLLATE utf8_general_ci;

Import

mysql --default-character-set=utf8 -u root -p MyDB_utf8 < dump_utf8.sql

VIM

Save with DOS newline (\r\n)

:set ff=dos
:w

Save with UNIX newline (\n)

:set ff=unix
:w

Set tab length

:set ts=4

Change to spaces instead of tab

:set et
:retab!

Change to tab instead of spaces

:set noet
:retab!

Save as HTML with syntax highlighting (opens in a new window that can be saved)

:runtime! syntax/2html.vim

Commands

A = Insert at end of row
I = Insert at beginning of row
a = Insert after current character
i = Insert before current character
r = Replace current character
o = Insert at new row after current row
O = Insert at new row before current row

SSH

Tunnel

 ssh -f server_name -L 3306:localhost:3306 -N

Reverse tunnel. This will listen on port 1100 on remote_server and forward it to local_server 1100.

ssh -nNT -R 1100:local_server:1100 remote_server

Only allow rsync in authorized_keys

command="/usr/bin/rsync --server --sender -vlogDtprz . /",no-pty,no-port-forwarding ssh-rsa ...

Using tunnel to connect to a printer on a server from a local machine

ssh -L 52631:localhost:631 server_name
http://localhost:52631

Lektor

Create new virtualenv and activate it

virtualenv venv
. venv/bin/activate

Test server/blog

lektor server
http://localhost:5000

Deploy

lektor deploy production

// Johan Söderberg