SSH
ssh user@host |
ssh user@host (port) |
Help
man (command) = Shows the manpages for the current command |
(Command) --help = Less detailed version of manpages |
whatis <command> -Gets short one line manual page to describe |
Searching
grep "TODO" files = Searches for TODO in files |
grep -r "TODO" dir = Searches recursively for TODO in the directory |
locate (file) = Finds all instances of file |
find (file) = Find all instances of file |
IO Redirection
command < file (Read input of command from file) |
command > file (Write output of command to file) |
command > /dev/null (Discard output of command) |
command >> file (Append output of file) |
command1 | command2 (Pipe output of command1 to command2) |
Touch
Create single file: touch example |
Create multiple files: touch example1 example2 |
Set current time and date of file: touch -a example |
Create file with specified time: touch -t YYMMDDHHMM.SS example |
User Additions
sudo useradd <username> |
sudo smbpasswd -a <username> |
DHCP Setup
sudo \cp /usr/share/doc/dhcp-server/dhcpd.conf.example /etc/dhcp/dhcpd.conf (Setup New Empty Config) |
Setup Static IP: ip addr add 192.168.114.1 dev br0; |
Setting up bridging: sudo dnf install bridge-utils |
sudo brctl addbr br0; sudo brctl addif enp1s0; sudo brctl addif eno1; sudo ifconfig br0 up |
Check history of commands
Check if is a File, Directory, or Symbolic Link
if [ -d "$1" ] (Directory) |
elif [ -h "$1" ] (Symbolic Link) |
elif [ -f "$1" ] (File) |
Executing Scripts
Make script executable: chmod +x <scriptname> |
./<scriptname> - Execute script |
Networking
netstat -rn -displays destination network and hosts of routing table |
ifconfig lo 127.0.0.1 . -assigns loopback to 127.0.0.1 |
ifconfig eth0 127.17.75.20 . -assigns ethernet device to IP |
route add default gw 128.17.75.98 . -adds route to routing table |
Clear
clear (clears command line) |
|
|
Create/Add/Remove Directories
mkdir (dir) [Creating Directory] |
pwd [Show current directory] |
cp file1 file2 [Copies file1 to file 2] |
cp -r dir1 dir2 [Copies dir1 to dir2] |
rm file/ rm -r dir [Remove file or remove directory] |
Permissions
chmod ugo=rwx file = Changes permissions of file to Read, write, and execute for the User,Group, and all Others. This command can have many iterations. |
chmod 777 = First digit is read(4+2+1), second is write(4+2+1), and the third is (4+2+1). Many combinations of numbers can be used. |
Systemd
sudo systemctl start/stop/restart 'nginx.service' . -start, stop, and restart service with systemctl |
sudo systemctl enable/disable 'nginx.service' -disables or enables service |
systemctl list-units --all . -lists all units systemd has loaded into the system |
journalctl . -view all log entries |
sudo systemctl edit 'nginx.service' . -modify service directly |
Performance Monitoring
Display and manage top processes: top |
Display processor related statistics: mpstat 1 |
Display virtual memory statistics: vmstat 1 |
Display the last 100 syslog messages: tail 100 /var/log/messages |
Monitor all traffic on port 80: tcpdump -i eth0 'port 80' |
List files opened by user: lsof -u user |
Display free and used memory ( -h for human readable, -m is MB, -g is GB): free -hmg |
Network Diagnostics
dig oreilly.com -returns information help by domain |
Display absolute path of files or links
DHCP Config File
option domain-name “sap.cslab.moravian.edu”; |
option domain-name-servers sap.cslab.moravian.edu; |
authoritative; |
log-facility local7; |
Show users currently logged in to host
Arrays
Creating an array: array=("This" "is" "an" "array") |
Print element in array: echo ${array[0]}, echo ${array[1]} |
Expand all elements of array: printf ${array[@]} |
Delete array value: unset ARRAY[1] |
Exit command in Script
Exit 0 (Standard exit) |
Exit (1,2,3,etc.) - If you want to customize for your script |
Directories to Know
/ - Root |
/bin – Essential User Binaries |
/boot – Static Boot Files |
/dev – Device Files |
/etc – Configuration Files |
/home – Home Folders |
/lib – Essential Shared Libraries |
|
|
Navigating Files/Directories
ls [list files in a directory] |
ls -al [Formats files in a list and shows hidden files |
cd (dir) [Change directory] |
pwd [Show current directory] |
more (file) [Outputs contents of a file] |
Firewalld
firewall-cmd --add-service='service name' -Adds system service to firewall protection |
If-then-exit
if []; then echo "" exit 1 . -if-then-exit commands for scripts |
Kerberos Install
sudo dnf install ntp -y |
sudo dnf install krb5-libs krb5-server krb5-workstation |
Edit /var/kerberos/krb5kdc/kadm5.acl Change /admin@EXAMPLE to /admin |
sudo /usr/sbin/kdb5_util create -s |
Test
Example to test if directory was created: test -d /tmp/temp_dir |
How long system has been running
Download files from the web
Reading from Standard Input with xargs
find . -mtime -1 -type f -print | xargs tar --create --gzip --file=$DESTDIR$FIL> : Reads items from the standard input |
DNF
sudo dnf install <package> -useful for installing new packages from the command line |
sudo dnf upgrade <package> -upgrades or updates given package |
sudo dnf remove <package> -removes the selected package |
Crontab
cron -e (Find timed services) |
crontab -l 2>/dev/null | grep -q "0 0 * crontab <command> (Ensure crontab is not outputting any else but the job to run) |
Setting Up JupyterHub
jupyterhub --generate-config (Generates jupyterhub_config.py) |
jupyterhub -f /etc/jupyterhub/jupyterhub_config.py (Start jupyterhub using config) |
c.JupyterHub.ip = '192.168.1.2' c.JupyterHub.port = 443 (Change IP and Port in config FIle) |
Dick Usage
df -h (Shows used disk space of certain file or directory) |
Tar
tar -x (Exract files) -v (verbose) z (zipped file) -f (use tar archive for operation) |
|
|
Shortcuts
Ctrl+C = Ends current process |
Ctrl+Z = Stops current process, but can be resumed |
Ctrl+D = Log out of current session |
exit = Log Out of current session |
Up/Down Arrows = Navigate through previous commands |
Check if argument is a variable
Functions
Create function in command line example: bash$ home() { printf '%s\n' "$HOME" ; } |
-- in a function: The option terminator string |
"$@" expands to all of the arguments given to the function: printf '%s\n' "$@" |
Save defined fucntion in bash: declare -f home |
When writing functions in scripts, it is best to instantiate them at the top of the script so no errors are produced. |
Check if argument is a command
if command -v "$1" >/dev/null; then |
Universal Home Directory to use in Scripts etc.
Find
find -mtime (Files access within certain time) -type (Look for specific file type) |
Shebang
#!/bin/bash -normal shebang of commented file |
echo "Hello World!" -display line of text |
#comment -# is the standard way to command in text editor |
variable_name="Sebastiaan" -standard way to establish variables |
Alias
Create an alias example: alias 11='ls --color=auto' |
Chec k whether command is an alias: type -a 11 |
IpConfig
ipconfig -a -displays all networks and interfaces |
ping host -send a ping signal to the host |
ifconfig eth0 -displays eth0 address and details |
Adding Google Authenticator to JupyterHub
Add this command to JupyterHub config: from oauthenticator.google import GoogleOAuthenticator c.JupyterHub.authenticator_class = GoogleOAuthenticator |
Customize domain name: c.GoogleOAuthenticator.hosted_domain = ['jupyterhub.com'] |
Installing oauth: dnf install oauthenticator |
File Transfers
Secure copy example.txt to the /tmp folder on server: scp example.txt server:/tmp |
Copy .zip files from server to the local /tmp folder: scp server:/var/www/.zip /tmp |
Copy all files and directories recursively from server: scp -r server:/var/www /tmp |
Synchronize /home to /home/.backups: rsync -a /home /backups/ |
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment