I'm not responsible for any disaster you may cause. Use at your own risk!
- Linux Commands Cheat Sheet
- Most common commands
- Getting help
- Logout
- Exit
- Shutdown and reboot
- Print working directory
- Go to directory
- List files
- Create file
- Edit file
- Print file
- Create directory
- Remove file
- Remove directory
- Remove directory and its content
- Change password
- Run as Super-User
- Switch to Super-User
- Update and upgrade packages
- Find files and commands
- List processes
- Kill process
- Connect to SSH [with PKA]
- Set up public key authentication
- About
- Most common commands
help
COMMAND --help
apt --help
man COMMAND
man apt
logout
exit
shutdown TIME
shutdown now
shutdown 11:00
shutdown -r TIME
shutdown -r now
shutdown -r 23:00
shutdown -c [MESSAGE]
shutdown -c
shutdown -c "Cancelled scheduled shutdown"
pwd
"~/" is used instead of user's home directory (/home/user)
~/.ssh/id_rsa
= /home/user/id_rsa
"/" is used instead of root directory (/)
/.ssh
!= .ssh
unless working directory is root (/)
cd PATH
cd /mnt/c
To go back to previous directory:
cd ..
ls -hal [PATH]
ls -hal /mnt/c
touch PATH
nano PATH
cat PATH
mkdir PATH
rm PATH [PATH] [...PATH]
rm /abc/test.txt
rm /abc/text.txt test.txt app.zip
rmdir PATH [PATH] [...PATH]
rm -rf PATH [PATH] [...PATH]
passwd [USERNAME]
sudo COMMAND
sudo touch test.txt
su
sudo apt-get update && sudo apt upgrade
For the locate
command to work correctly, you will first need to update the file indexing database using the command:
updatedb
locate
command is used for finding files.
locate FILENAME
locate abc.txt
which
command is used for finding command files/links, or checking whether a command exists in PATH.
which COMMAND
find
command is used for finding directories.
find DIRECTORY
Use these commands to get the PID (process ID) of a process, so that you can kill/restart the process.
ps -A
If there are too many processes, use the following command to scroll at your own pace:
ps -A | less
If you want to find a process by name:
ps -A | grep firefox
kill PID
pkill PID
To kill a process tree:
killall PID
To kill a graphical process:
xkill PID
If you don't use [-p PORT]
option, the default SSH port is used: 22
If you don't use [-i PRIVATE_KEY_FILE]
option, the default key file is used (assuming it exists): ~/.ssh/id_rsa
You must set up PKA (Public Key Authentication) before these commands
ssh [-p PORT] [-i PRIVATE_KEY_FILE] USERNAME@SERVER_IP
ssh -p 2222 -i ~/.ssh/server-a-key [email protected]
You can use this highly secure method to connect to GitHub or SSH.
DO NOT LEAVE YOUR PRIVATE KEY id_rsa
IN THE DEVICE YOU WOULD LIKE TO CONNECT TO. PRIVATE KEY IS YOUR HOUSE KEY, DO NOT LEAVE ANY COPIES OR ITSELF AT HOME!
ls -la ~/.ssh
If you see a pair of files named like: something
and something.pub
, then that means there is already a key pair.
Most commonly found as: id_rsa
and id_rsa.pub
.
Make sure you are not using the current key pair in any application/service etc. If you complete this step, THERE IS NO GOING BACK. If you think this key pair is still safe to use, please skip this step.
rm id_rsa id_rsa.pub
ssh-keygen
Follow the steps. I will be using the default values, and maybe a passphrase.
cat ~/.ssh/id_rsa.pub
Select and copy the output.
chmod 600 ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa.pub
You can skip this step, however if you see "Insecure Key" error, please complete this step.
-
On the device which you would like to connect to (server etc.), create a file named
authorized_keys
and open for editing; using the command:nano ~/.ssh/authorized_keys
-
Paste the public key you copied in step 4. Press
Ctrl + X
, thenY
, and lastly pressENTER
to save.
- Open GitHub on your browser
- Click on your profile picture on top right corner
- Click on Settings
- Go to SSH and GPG keys tab
- Click New SSH key button, name your key and paste the public key you copied in step 4
- Save by clicking Add SSH key
- Now you can try connecting to
[email protected]
using [[#Connect to SSH with PKA]] method. You must have your private key to be able to do this step. You should see:
Hi USER! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.
For some reason, whenever sudo apt-get update && sudo apt upgrade
command to update the packages is run, it gives E: Failed to fetch store:/var/lib/apt/lists/partial/http.kali.org_kali_dists_kali-rolling_main_binary-amd64_Packages.gz Hash Sum mismatch
and E: Some index files failed to download. They have been ignored, or old ones used instead.
errors. To fix this, you need to execute the following commands:
sudo bash
mkdir /etc/gcrypt
echo all >> /etc/gcrypt/hwf.deny
sudo apt-get update
Made by Adil Atalay Hamamcioglu, after failing to memorize even the simplest, shortest commands ;_; .