Skip to content

Instantly share code, notes, and snippets.

@ant-rod-silva
Last active August 14, 2021 19:54
Show Gist options
  • Save ant-rod-silva/7fa93d9db86f3699390a035e0e2bc7f5 to your computer and use it in GitHub Desktop.
Save ant-rod-silva/7fa93d9db86f3699390a035e0e2bc7f5 to your computer and use it in GitHub Desktop.

Remove user

rmuser jru

chsh entry inconsistent

pwd_mkdb -p /etc/master.passwd

ZSH

pkg install zsh
chsh -s /usr/local/bin/zsh
nano ~/.zshrc
ZSH_THEME="aussiegeek"

alias ls='/bin/ls --color=always'
alias df="df -h"
alias du="du -h"
alias top="htop"
alias updatedb='/usr/libexec/locate.updatedb'
alias cls='clear'
alias vi='vim'
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias dir='ls -ahlFGT'
alias del='rm'
alias copy='cp'
alias md='mkdir'
alias rd='rmdir'
alias free='free -m'
alias gcheck='git checkout'
alias gpull='git pull'
alias gpush='git push'
alias gpushmaster='git push origin master'
alias gpullmaster='git pull origin master'
alias gadd='git add'
alias gcomm='git commit -am \$1'
alias gstat='git status'
alias gname='git config user.name \$1'
alias gemail='git config user.email \$1'
alias ggname='git config --global user.name \$1'
alias ggemail='git config --global user.email \$1'

Install PostgreSQL 10 on FreeBSD

see installed packages

pkg info | grep postgresql

remove installed packages

pkg delete -fy postgresql96-client
pkg delete -fy postgresql96-contrib
pkg delete -fy postgresql96-server

install postgresql 10

pkg install postgresql10-server

It will create the user postgres and group postgres UID 770 for you.

add postgresql_enable="YES" to your /etc/rc.conf

sudo sysrc postgresql_enable=yes
/usr/local/etc/rc.d/postgresql initdb
/usr/local/etc/rc.d/postgresql start

CREATE USERS AND DATABASES

Log into the pgsql account created for you when you installed PostgreSQL.

su postgres

Create a PostgreSQL user account.

createuser -P user_test

Create a database suppling the owner of the database.

createdb db_test -O user_test

ALLOWING REMOTE CONNECTIONS

By default you will not be able to log into the database server unless you are on the local server. If your application is hosted on the same server as the database, you can skip this section. Configure PostgreSQL to listen for database connections on all system IP addresses by adding the following line to postgresql.conf file. This file is located in the directory where the database is initialized. For FreeBSD 11.0-RELEASE and PostgreSQL 9.6 this location will be /var/db/postgres/data96/postgresql.conf unless you specified another location.

listen_addresses = '*'

Next you need to edit pg_hba.conf file in the same directory.

Restart the service for the changes to take effect.

/usr/local/etc/rc.d/postgresql restart

Be sure to install the postgres client on the host computer. Now test your connection from your other host computer.

psql -h localhost -U user_test db_test

How to install VMware tools on FreeBSD server

There are multiple options how to install VMware tools on FreeBSD but I personally use Open VM Tools native FreeBSD package as using Open VM Tools is actually the latest VMware's recommendation for unix like systems which is the case of FreeBSD.

You have to switch to administrator account (root)

su -l root

and install Open VM Tools by FreeBSD package manager

pkg install open-vm-tools-nox11

To run the Open Virtual Machine tools at startup, you must add the following settings to your /etc/rc.conf

vmware_guest_vmblock_enable="YES"
vmware_guest_vmhgfs_enable="NO"
vmware_guest_vmmemctl_enable="YES"
vmware_guest_vmxnet_enable="YES"
vmware_guestd_enable="YES"

How I got Xorg mouse and keyboard working on FreeBSD (VMWare)

I added these four lines to my /etc/rc.conf file.

moused_enable="NO"
moused_nondefault_enable="NO"
hald_enable="YES"
dbus_enable="YES"

How to upgrade FreeBSD 11 to 12

First note down the FreeBSD version by running the following commands:

freebsd-version
uname -mrs

Make sure both FreeBSD base and packages are updates:

freebsd-update fetch install
pkg update && pkg upgrade

Type the following freebsd-update command:

freebsd-update -r 12.0-RELEASE upgrade

Does this look reasonable (y/n) y Once everything downloaded, merged in a directory, it is time to commit changes to the disk, run:

freebsd-update install

Once the system has come back online, restart freebsd-update using the following command to remove all old shared libraries and object files:

freebsd-update install

Sample outputs:

Installing updates...
Completing this upgrade requires removing old shared object files.
Please rebuild all installed 3rd party software (e.g., programs
installed from the ports tree) and then run "/usr/sbin/freebsd-update install"
again to finish installing updates.

Now base system has been updated. It is time to update all binary packages too. Simply run the following pkg command:

pkg-static install -f pkg
pkg update
pkg upgrade

One more last time and you are done:

/usr/sbin/freebsd-update install

How to verify FreeBSD 11 to 12 upgrade Make sure all services are running:

ps aux
sockstat -l
sockstat -4
sockstat -6
netstat -a -n | grep LISTEN
top
Check out for errors in log file using the cat command/grep command/egrep command and other tools:
tail -f /var/log/messages
grep error /path/to/app
egrep -i 'err|warn|cri' /var/log/messages

See version:

uname -mrs
freebsd-version

sublime text 3

cd /usr/ports/editors/linux-sublime3/ && make install clean
  1. You need to be root. So open a terminal and type:
su

It will give you a shell with root rights. Then you won't have to type sudo each time for the next commands.

  1. Create a directory for the tmpfs filesystem. For instance:
mkdir /tmpfs
  1. Edit the /etc/fstab (with vi for instance) to add the following line at the end of the file:
tmpfs     /tmpfs     tmpfs   rw,mode=777   0   0
  1. Mount the tmpfs filesystem:
mount /tmpfs
  1. Edit the file /etc/devfs.conf (with vi for instance) to add the following line at the end of the file:
link   /tmpfs   shm
  1. Restart devfs
/etc/rc.d/devfs restart
reboot
  1. Try to run sublime -w, that should work.

ports

portsnap fetch
portsnap extract
pkg install psearch

How do I install the port called apache22? To install the postgresql11-server port:

cd /usr/ports/databases/postgresql11-server/ && make install clean

How do I remove the port called postgresql11-server?

cd /usr/ports/databases/postgresql11-server/ && make deinstall

To remove configuration files as well:

# make rmconfig

How do I update installed ports? Keeping your applications up-to-date is very important. You need to use the portmaster. First install it:

cd /usr/ports/ports-mgmt/portmaster
make install clean

OR

pkg install portmaster

Okay, update the ports tree:

portsnap fetch update

archivers

https://www.freebsd.org/ports/archivers.html

pkg install p7zip p7zip-codec-rar rar arc arj ark bzip bzip2 dar deco dzip engrampa grzip gtar gzip libarc libcabinet  liblz4 libunrar libzip unace unrar unzip untar zip

Como Instalar o MATE Desktop

pkg install xorg mate mate-desktop slim

Efetuadas configurações no /etc/rc.conf com o Easy Editor (ee)

ee /etc/rc.conf

Adicionado ao final do arquivo os comandos

hald_enable="YES"
dbus_enable="YES"
slim_enable="YES"

Configuramos o $USER para aceitar o comando su e poder logar como root

pw groupmod wheel -m marcos

Criação do .xinitrc

ee ~/.xinitrc

E editamos o arquivo com os comandos

export LC_ALL=pt_BR.UTF-8
export LANGUAGE=pt_BR.UTF-8
export LANG=pt_BR.UTF-8
exec mate-session

Depois de dar um reboot no sistema shutdown -r now levantamos a interface gráfica(GUI) MATE Desktop com o comando startx


useful shortcuts

cd /home/osboxes
ln -s /etc/hosts hosts
ln -s /etc/rc.conf rc.conf
ln -s /usr/local/etc/php.ini php/php.ini
ln -s /usr/local/etc/php/99-custom.ini php/99-custom.ini
ln -s /usr/local/etc/php-fpm.d/www.conf php-fpm/www.conf
ln -s /usr/local/etc/nginx/nginx.conf nginx/nginx.conf
ln -s /usr/local/www/nginx/ www

see all users and groups

awk -F":" '{print $1}' /etc/group
awk -F":" '{print $1}' /etc/users

updatedb e locale

/usr/libexec/locate.updatedb
locate nginx.conf

D-Bus library appears to be incorrectly set up; failed to read machine uuid: Failed to open “/var/lib/dbus/machine-id”

A simple fix for once. I usually see this problem when I’ve installed a barebones / headless system and then wanted to add xorg to it later.

To fix it, run

dbus-uuidgen > /var/lib/dbus/machine-id

FreeBSD add a user to group

pw usermod [username] -G video,wheel
id [username]

Solving the FreeBSD “su: Sorry” Problem

The solution is to restart FreeBSD in single user mode and then make the change as root. This can be done by following the steps below:

Step 1: Restart the server, then press 2 to boot into single user mode.

Step 2: Make the file system writable by running the following command:

mount -u -w /

Step 3: Assuming your user is called sysadmin, run the following command to add the user to the wheel group:

pw usermod [username] -G wheel

Step 4: Restart the server and test the su command.

su

As you can see from the output above, the su command now switches to the root user account when running it as the sysadmin user.


Install PHP 7, Python 2.7, Python 3

pkg install php72
pkg install php72-extensions

Another option is installing individual PHP extensions as per your web application or software project needs. One can search PHP 7.2 extensions using the pkg command and grep command/egrep command

pkg search php72 | grep gd
pkg search php72 | egrep -i --color 'gd|mysqli|openssl'
pkg search php72 | egrep --color -i -- '-(gd|mysqli|openssl|memcached|opcache|json|mbstring|imagick|xml|zip|composer|igbinary)-'

Simply install it:

pkg install php72-composer php72-gd php72-json
pkg install python
pkg install python3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment