Skip to content

Instantly share code, notes, and snippets.

@refo
Last active February 2, 2018 12:00
Show Gist options
  • Select an option

  • Save refo/ac005b8cc91eae027a7512b38db023b9 to your computer and use it in GitHub Desktop.

Select an option

Save refo/ac005b8cc91eae027a7512b38db023b9 to your computer and use it in GitHub Desktop.
Linux notes

Authorized keys

mkdir -m 700 /root/.ssh
echo "my public key" > /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
restorecon -r /root/.ssh

source: https://www.centos.org/forums/viewtopic.php?t=2480

Create an HTTP proxy over SSH

# Create a socks proxy to remote server
ssh -D 1080 -C -q -N <remote>
# Create an http proxy over socks
polipo socksParentProxy=localhost:1080
# Test the HTTP proxy
http_proxy=localhost:8123 curl http://ifconfig.co

As a result, we've two proxy servers running on localhost:

SOCKS 5 proxy localhost:1080

HTTP proxy localhost:8123

convert between SSH2 and OpenSSH

Needs OpenSSH to be installed on the system

SSH2 to OpenSSH

ssh-keygen -i -f /path/to/Identity.pub > ~/.ssh/id_rsa.pub

OpenSSH to SSH2

ssh-keygen -e -f /path/to/id_rsa.pub > /path/to/Identity.pub

sudoers

Allow <user> to run a bash script as "root" without password
<user>	ALL=(root) NOPASSWD: /path/to/script

pay attention to <tab> after <user>

Swap

# List configured swap files
swapon -s

# Disable all swapfiles
swapoff -a

# Create a 1GB empty file
dd if=/dev/zero of=/swapfile bs=1M count=1024

# Make that empty file a swapfile
mkswap /swapfile

# Enable swapfile for system to use
swapon /swapfile

Random Password

LC_CTYPE=C tr -dc A-Za-z0-9 < /dev/urandom | head -c${1:-32};echo

Create User

useradd -d /home/user -m -s /bin/bash user
passwd user

Disable or change user shell

# disable
chsh -s /bin/false user
# change
chsh -s /bin/zsh user

Set defult locale

printf \
"export LANGUAGE=en_US.UTF-8\n\
export LANG=en_US.UTF-8\n\
export LC_ALL=en_US.UTF-8\n" \
>> /etc/environment

~/.ssh/config

Host vagrant
	HostName vagrant.local
	User ubuntu
	Port 2222
	IdentityFile /Users/refik/Sites/vagrant/xenial/.vagrant/machines/web/virtualbox/private_key
  
upstream app {
server 127.0.0.1:3001;
keepalive 8;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
server_tokens off;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://app/;
proxy_redirect off;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment