System administration: Difference between revisions

Jump to navigation Jump to search
m
no edit summary
Tag: visualeditor
mNo edit summary
Line 32: Line 32:


== Set timezone ==
== Set timezone ==
<source lang="bash">
<syntaxhighlight lang="bash">
$ sudo timedatectl set-timezone America/Denver
$ sudo timedatectl set-timezone America/Denver
</source>
</syntaxhighlight>
== Composer ==
== Composer ==


Line 41: Line 41:
Composer is a PHP package management tool.  Usually needed for setting up web application development environment.
Composer is a PHP package management tool.  Usually needed for setting up web application development environment.


<source lang="console">
<syntaxhighlight lang="console">
$ cd
$ cd
$ mkdir bin
$ mkdir bin
Line 50: Line 50:
$ ./getcomposer
$ ./getcomposer
$ mv composer.phar composer
$ mv composer.phar composer
</source>
</syntaxhighlight>




Line 59: Line 59:
Create private/public SSH key file using the default bit encryption and with a comment. The command creates files under ~/.ssh folder.
Create private/public SSH key file using the default bit encryption and with a comment. The command creates files under ~/.ssh folder.


<source lang="bash">
<syntaxhighlight lang="bash">
$ ssh-keygen -C user@host.domain
$ ssh-keygen -C user@host.domain
</source>
</syntaxhighlight>




Line 68: Line 68:
The config file ~/.ssh/config stores information about various SSH connections, and allows the definition of hostname, username, ports, and other settings.
The config file ~/.ssh/config stores information about various SSH connections, and allows the definition of hostname, username, ports, and other settings.


<source lang="html5">
<syntaxhighlight lang="html5">
Host hostname1
Host hostname1
     HostName hostname1.domain.com
     HostName hostname1.domain.com
     User username1
     User username1
     Port 1234
     Port 1234
</source>
</syntaxhighlight>


== Adding a user to sudoers list ==
== Adding a user to sudoers list ==
Line 89: Line 89:
On Ubuntu distribution of GNU/Linux, you can uncomment force_color_prompt = yes line to use color prompts. The following is my personal favorite color configuration for the prompt.
On Ubuntu distribution of GNU/Linux, you can uncomment force_color_prompt = yes line to use color prompts. The following is my personal favorite color configuration for the prompt.


<source lang="bash">
<syntaxhighlight lang="bash">
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u\[\033[01;30m\]@\[\033[00;36m\]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u\[\033[01;30m\]@\[\033[00;36m\]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
</source>
</syntaxhighlight>


== Enable byobu ==
== Enable byobu ==


<source lang="bash">
<syntaxhighlight lang="bash">
$ byobu-enable
$ byobu-enable
</source>
</syntaxhighlight>


== Update .vimrc ==
== Update .vimrc ==


<source lang="vim">
<syntaxhighlight lang="vim">
syntax on
syntax on
set noexpandtab
set noexpandtab
Line 128: Line 128:
autocmd FileType php nnoremap <C-p> :call PhpDocSingle()<CR>
autocmd FileType php nnoremap <C-p> :call PhpDocSingle()<CR>
autocmd FileType php vnoremap <C-p> :call PhpDocRange()<CR>
autocmd FileType php vnoremap <C-p> :call PhpDocRange()<CR>
</source>
</syntaxhighlight>


=== awesome-vim ===
=== awesome-vim ===
For a preset of VIM development environment, awesome-vim is okay:<source lang="bash">
For a preset of VIM development environment, awesome-vim is okay:<syntaxhighlight lang="bash">
$ git clone --depth=1 https://github.com/amix/vimrc.git ~/.vim_runtime
$ git clone --depth=1 https://github.com/amix/vimrc.git ~/.vim_runtime
$ sh ~/.vim_runtime/install_awesome_vimrc.sh
$ sh ~/.vim_runtime/install_awesome_vimrc.sh
</source># Run inside vim: -- this will let you click and drag panes to resize or jump between (learning vim more and being able to jump panes
</syntaxhighlight># Run inside vim: -- this will let you click and drag panes to resize or jump between (learning vim more and being able to jump panes


<nowiki>#</nowiki> makes this unecessary, but i'm not that good yet.)
<nowiki>#</nowiki> makes this unecessary, but i'm not that good yet.)
Line 201: Line 201:


Install the LAMP stack
Install the LAMP stack
<source lang="bash">
<syntaxhighlight lang="bash">
$ sudo apt-get install tasksel
$ sudo apt-get install tasksel


$ sudo tasksel install lamp-server
$ sudo tasksel install lamp-server
</source>
</syntaxhighlight>


Install git and other PHP related extensions
Install git and other PHP related extensions
<source lang="bash">
<syntaxhighlight lang="bash">
$ sudo apt-get install git php5-mcrypt php5-xdebug php5-intl
$ sudo apt-get install git php5-mcrypt php5-xdebug php5-intl
</source>
</syntaxhighlight>


=== .gitconfig ===
=== .gitconfig ===
<source lang="html5">
<syntaxhighlight lang="html5">
[core]
[core]
   editor = vim
   editor = vim
Line 242: Line 242:
[merge]
[merge]
   defaultToUpstream = true
   defaultToUpstream = true
</source>
</syntaxhighlight>


== Change default shell ==
== Change default shell ==


<source lang="bash">
<syntaxhighlight lang="bash">
$ chsh
$ chsh
</source>
</syntaxhighlight>


== Edit passwd files ==
== Edit passwd files ==


<source lang="bash">
<syntaxhighlight lang="bash">
$ sudo vipw
$ sudo vipw
</source>
</syntaxhighlight>


= RHEL-specific =
= RHEL-specific =
Line 270: Line 270:
== Update the server ==
== Update the server ==


<source lang="bash">
<syntaxhighlight lang="bash">
$ sudo apt update && sudo apt -y full-upgrade && sudo apt-get -y autoremove
$ sudo apt update && sudo apt -y full-upgrade && sudo apt-get -y autoremove
</source>
</syntaxhighlight>


== Reconfigure console font ==
== Reconfigure console font ==


<source lang="bash">
<syntaxhighlight lang="bash">
$ dpkg-reconfigure console-setup
$ dpkg-reconfigure console-setup
</source>
</syntaxhighlight>


== Change the default editor ==
== Change the default editor ==
Line 284: Line 284:
Used by visudo and other programs for invoking an editor.
Used by visudo and other programs for invoking an editor.


<source lang="bash">
<syntaxhighlight lang="bash">
$ sudo update-alternatives --config editor
$ sudo update-alternatives --config editor
</source>
</syntaxhighlight>


== Change time zone ==
== Change time zone ==
Line 302: Line 302:
* First determine your own shell
* First determine your own shell


<source lang="bash">
<syntaxhighlight lang="bash">
$ tty
$ tty
</source>
</syntaxhighlight>


* Show all of your running processes
* Show all of your running processes


<source lang="console">
<syntaxhighlight lang="console">
$ ps -fu mhan
$ ps -fu mhan
UID        PID  PPID  C STIME TTY          TIME CMD
UID        PID  PPID  C STIME TTY          TIME CMD
Line 318: Line 318:
mhan    21939 21609  0 19:06 pts/3    00:00:00 ps -fu mhan
mhan    21939 21609  0 19:06 pts/3    00:00:00 ps -fu mhan
mhan    21580 21469  0 19:02 ?        00:00:00 sshd: mhan@pts/2
mhan    21580 21469  0 19:02 ?        00:00:00 sshd: mhan@pts/2
</source>
</syntaxhighlight>


* If I want to kill pts/2 then the PID to kill is 21580.
* If I want to kill pts/2 then the PID to kill is 21580.


<source lang="bash">
<syntaxhighlight lang="bash">
$ kill -HUP 21580
$ kill -HUP 21580
</source>
</syntaxhighlight>


Reference: https://kb.iu.edu/d/adqw (accessed on 10/5/2017)
Reference: https://kb.iu.edu/d/adqw (accessed on 10/5/2017)
Line 338: Line 338:
As an example, let's say the process of interest is ''qemu-system-arm''. You have to find out what PID (Process ID) is first.
As an example, let's say the process of interest is ''qemu-system-arm''. You have to find out what PID (Process ID) is first.


<source lang="bash">
<syntaxhighlight lang="bash">
$ pidof qemu-system-arm
$ pidof qemu-system-arm
3016
3016
</source>
</syntaxhighlight>


Then check what the current nice value of the process is:
Then check what the current nice value of the process is:
<source lang="bash">
<syntaxhighlight lang="bash">
$ ps -o pid,comm,nice -p 3016
$ ps -o pid,comm,nice -p 3016
   PID COMMAND        NI
   PID COMMAND        NI
  3016 qemu-system-arm  0
  3016 qemu-system-arm  0
</source>
</syntaxhighlight>


According to the output, the nice value of ''qemu-system-arm'' is 0. We want to '''decrease''' the nice value to dedicate more CPU time to it. However, you need sudo privilege in order to give a negative value for a nice value, even though you do not need such privilege for increasing the nice value to something above 0. Here we decrease it to -10.
According to the output, the nice value of ''qemu-system-arm'' is 0. We want to '''decrease''' the nice value to dedicate more CPU time to it. However, you need sudo privilege in order to give a negative value for a nice value, even though you do not need such privilege for increasing the nice value to something above 0. Here we decrease it to -10.


<source lang="bash">
<syntaxhighlight lang="bash">
$ sudo renice -10 -p 3016
$ sudo renice -10 -p 3016
</source>
</syntaxhighlight>


To set a permanent priority on all processes for a specific user or a group you can update ''/etc/security/limits.conf'' file.
To set a permanent priority on all processes for a specific user or a group you can update ''/etc/security/limits.conf'' file.
Line 372: Line 372:
== Pull a random line from a log ==
== Pull a random line from a log ==


<source lang="console">
<syntaxhighlight lang="console">
$ shuf -n 1 /etc/pihole/gravity.list
$ shuf -n 1 /etc/pihole/gravity.list
</source>
</syntaxhighlight>


== Viewing of the log in real time ==
== Viewing of the log in real time ==


<source lang="bash">
<syntaxhighlight lang="bash">
$ tail -f /var/log/some.log
$ tail -f /var/log/some.log
</source>
</syntaxhighlight>


[[Multitail]]
[[Multitail]]
Line 430: Line 430:
== Remove some columns from an output ==
== Remove some columns from an output ==


<source lang="bash">
<syntaxhighlight lang="bash">
$ ls -l | awk '{print $3 " " $9}'
$ ls -l | awk '{print $3 " " $9}'
</source>
</syntaxhighlight>


== Make a backup without typing the full path twice ==
== Make a backup without typing the full path twice ==
Line 438: Line 438:
To make a backup without typing the full path twice with the suffix .orig
To make a backup without typing the full path twice with the suffix .orig


<source lang="bash">
<syntaxhighlight lang="bash">
$ cp /long/path/to/file/name{,.orig}
$ cp /long/path/to/file/name{,.orig}
</source>
</syntaxhighlight>

Navigation menu