huh...
UtoECat's trashpile of manuals, tips and configurations
back homeVIM configurations and tricks
-
My vim config
(highlighted) |
(curl-compatible raw version)
A very barebones configuration with a default-shipped selected color-theme that is okay-ish looking.
However, if you would just clone this vimrc to your system - nothing would happen.
That's because this vim config respects an enviroment variable called VIM_USER, that should be set to "utoecat" to work, aka:export VIM_USER="utoecat" # you may do this in .bashrc but there are bettwer ways!Now... Why on earth would you like to do that? Well...
vim
The reason is quite simple: multiple developers using the same account. Now, this is not relevant on a local computer but very much on a server. Combined with tweaking SHH configs to autoexport this variable you can achieve flawless and automatic behaviour, where different administrators will have their own configs, and new administrators will have vanilla vim configuration by default, as it is intended.
Additionally, this script has very useful key combinations to allow to copypaste selected region from the terminal. You can look at them in the vimrc file itself. - Export highlighted html snippets of code
Yes, you can do that with vim. You shall either open existing properly highlighted file, or create new temorary one, save it, and run this command:echo 'export VIM_USER="utoecat"' > test.shThis will open vim with second window of generated html. It won't be a valid html page (though you can fix that by removing let g:html_no_doc=1) but it's more than enough for our purposes.
# we do a lot of let's here to remove annoying shit
# and to not depend on a default configuration
vim -c "let g:html_use_css = 0" -c 'let g:html_no_doc=1' -c 'set nonumber' -c 'set norelativenumber' -c ":TOhtml" test.sh
You copypaste that into your actual html page, wrapping it all with appropreate font and background color. I prefer to use this div for that:<div style="background-color:303030; color:#ffffff; font-family: RobotoMono, monospace">You should adjust this to your colorscheme. You can also change clorscheme right in the command arguments. You should be able to guess from the given examples how to do that :)
<!-- paste here -->
</div>
Now, this isn't perfect fully automated tool, but there is a reason for that. It wouldn't be difficult to shit-code some php to wrap this vim command, but here are reasons why you SHOULD NOT do that:- tohtml vim plugin is slow
- vim is PROBABLY not safe to expose to arbitrary input files from a public internet endpoint.
- You should always pre-generate your pages anyway. And you can use any tool for that, even pure bash scripts
- I strongly prefer doing it manually. If i would be required to serve a tonn of highlighted files, i may've changed my mind on that. Not yet though.
SSH and SSHD
-
Recommended deviations from deafult-shipped config.
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value.
Include /etc/ssh/sshd_config.d/*.conf
#Port 22 # not really useful to change, since all malicious bots do port scanning anyway nowadays
PermitRootLogin yes # you better change this to no once you setup developer account and set strong password on it, add it to sudoers and then remove password authentication altogether from the server. so that you would need to use sudo and put down developer account password to login. However, i am lazy and for my personal servers i limit myself with just pubkey auth on root.
#StrictModes yes # NEVER TURN THIS OFF!!! On by default.
# you may adjust theese if you experience too heavy ssh traffic / spam
#LoginGraceTime 2m
#MaxAuthTries 6
#MaxSessions 10
#PubkeyAuthentication yes # Highly recommended. On by default.
# SSHD can be configured to use certificates for login, however
# you should not bother with that too much, since it's very niche
# thing and not as widespread or tested.
# Or maybe it is tested but is EXTREMELY easy to misconfigure. See:
# https://security.stackexchange.com/questions/254193/openssh-authorizedprincipalsfile-allows-any-user
#AuthorizedPrincipalsFile none
# RECOMMENDED once you've set up your pubkeys
PasswordAuthentication no
#PermitEmptyPasswords no # RECOMMENDED. Off by default
# (beware issues with some PAM modules and threads) LMAO who put this
# into production sshd then???
KbdInteractiveAuthentication no
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and KbdInteractiveAuthentication to 'no'.
UsePAM yes
#AllowAgentForwarding yes # can be misused, but keep it for compatibility
#AllowTcpForwarding yes # very useful for testing and stuff, keep it
#GatewayPorts no # only set to clientspecified if you REALLY need this
X11Forwarding no # most servers have no graphical apps anyway
#PrintLastLog yes # just for your sanity
#TCPKeepAlive yes # do not disable this!
#PermitUserEnvironment no # do NOT enable this!!!!1
#Compression delayed # either this or turn it off completely.
ClientAliveInterval 30 # increase those in case of bad internet connection!
ClientAliveCountMax 3 # same fixes for bad internet connectivity. may be a trade off between more stable connectivity and spam resistance.
#PermitTunnel no # no, and ssh also sucks as a vpn tunnel anyway
# Allow client to pass locale environment variables
# NOTE: VIM_USER is added here for our vim config support
# if not added here - it will be ignored by the server and
# you would need to do manual export VIM_USER="..." every login
AcceptEnv VIM_USER LANG LC_*
# override default of no subsystems
# used for sshfs i guess... i forgot already why
# anyways SAFE ftp is useful anyway. Sometimes. So keep it.
Subsystem sftp /usr/lib/openssh/sftp-server
# NOTE: do NOT replace your sshd_config with this! It may have
# config options set to patch some bugs provided by either your
# distribution mainteiners or other sysadmins. Manually look if
# variables like those were set any other values and why, and if
# they are not ound in /etc/sshd_counfig then add them at the end
# one by one. Also read recent documenttion about those variables
# in case ssh developers changed something / added new recommendations
Read the note at the end, again. For the same reason i do not provide a raw-text link on that file.
Now for the user config (on the ssh clients)# ~/.ssh/config
Host *
SetEnv VIM_USER=utoecat
Of course, if you've changed VIM_USER check in your .vimrc then put replace "utoecat" with an appropreate value here. -
Setting up pubkey-based authentication (on the client)
To not confuse shells
You better use differnet terminals for remote, but that's not always an option, and it's annoying.
So, instead, you better at least change the PS1 shell variable and motd as a last resort of mental
help for ya to not confuse local and remote production server terminals
Example below is for Debian, but can likely be adapted for others with ease.
Below only commented output of the files is shown, you shall create the same files in the same
locations with a similar content for all this to work.
So, instead, you better at least change the PS1 shell variable and motd as a last resort of mental
help for ya to not confuse local and remote production server terminals
Example below is for Debian, but can likely be adapted for others with ease.
Below only commented output of the files is shown, you shall create the same files in the same
locations with a similar content for all this to work.
cat /etc/profile.d/custom_ps1.sh
# export PS1="\[\033[41m\]\u@\h:\w\\$ <PROD> \[\033[0m\]"
#
cat /etc/motd
#
# The programs included with the Debian GNU/Linux system are free software;
# the exact distribution terms for each program are described in the
# individual files in /usr/share/doc/*/copyright.
#
# Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
# permitted by applicable law.
#
#>>>>>>>>>>>>>>>>>>> THIS IS A PRODUCTION SERVER <<<<<<<<<<<<<<<<<<<<<
#>>>>>>>> CHECK YOUR COMMANDS MULTIPLE TIMES BEFRORE RUNNING <<<<<<<<<
root@server-name:~# <PROD>
logout
Connection to server-name closed.
# export PS1="\[\033[41m\]\u@\h:\w\\$ <PROD> \[\033[0m\]"
#
cat /etc/motd
#
# The programs included with the Debian GNU/Linux system are free software;
# the exact distribution terms for each program are described in the
# individual files in /usr/share/doc/*/copyright.
#
# Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
# permitted by applicable law.
#
#>>>>>>>>>>>>>>>>>>> THIS IS A PRODUCTION SERVER <<<<<<<<<<<<<<<<<<<<<
#>>>>>>>> CHECK YOUR COMMANDS MULTIPLE TIMES BEFRORE RUNNING <<<<<<<<<
root@server-name:~# <PROD>
logout
Connection to server-name closed.
more stuff is coming soon