Important CLI commands

Here are some of the important CLI commands I encounter while working on projects that includes SSH keys and Github on cloud servers.

cd ~/.ssh

This command will take you to the root directory.


ssh-keygen -t ed25519 -C "support@adnan-tech.com" -f ~/.ssh/adnan_tech_com_ed25519

This will generate an SSH key in the current directory. It will ask for file name and password, you can press enter to set the name as default (id_ed25519 and id_ed25519.pub) and password as empty (no password).

If you are working on a cloud server, you may encounter a problem where you have to reboot your server. In some cloud providers, the SSH keys generated in .ssh folders are deleted after reboot.

Make sure to add the adnan_tech_com_ed25519 and adnan_tech_com_ed25519.pub in your .gitignore, otherwise, they will be uploaded on the repository.


chmod 600 ~/.ssh/adnan_tech_com_ed25519

Sometimes, when you try to execute some function based on that key, it will return an error “permissions for the key are too open”. Above command will set the permissions to 600 and you will be good to go.


cat ~/.ssh/adnan_tech_com_ed25519.pub

In order to view the SSH key, you can run the above command. This will show you the public key, you can safely add it in your Github > Settings > SSH keys page.


GIT_SSH_COMMAND="ssh -i ~/.ssh/adnan_tech_com_ed25519 -o IdentitiesOnly=yes" git push origin main

If you do created your SSH keys in your current directory and not in .ssh folder, then git pull or git push commands won’t work if your origin is SSH. But you can explicitly tell the git to use the SSH file in your current directory.


ssh-keygen -R adnan-tech.com

If you get the following error, you can run the above command to remove the previous fingerprint from your known hosts and run the git push command again.

Error: ECDSA host key for adnan-tech.com has changed and you have requested strict checking.
Host key verification failed.


git config --global user.email "support@adnan-tech.com"
git config --global user.name "Adnan Afzal"

These commands often mentioned by the git itself when you try to write a commit message and you are not logged-in in the terminal.


unzip file.zip -d file

If you uploaded a zip file from file manager and do not see an option to extract (some hosting providers do not have extract option), then you can use the above command to extract it. It will extract “file.zip” to a folder “file”.


Push via SSH to Github

First, list all the SSH keys generated from your computer.

ls -al ~/.ssh

Above command will display a list of all SSH keys generated and saved in your computer. It will display something like this:

list all SSH keys

Then you need to go to Github -> Settings -> SSH and GPG keys. There, if you already have an SSH key attached to your account, you will see something like this:

SSH key on Github

Otherwise, you can add your newly generated SSH key to Github. This is the fingerprint of your SSH key.

Then you need to run the following command to display the fingerprint of each SSH key:

for key in ~/.ssh/*.pub; do echo "$key"; ssh-keygen -lf "$key"; echo ""; done

It will display something like this:

SSH key fingerprint

Find the SSH key that matches the fingerprint on Github. Copy that SSH key from ~/.ssh to your project folder. Then run the following command to push using your SSH key:

GIT_SSH_COMMAND="ssh -i id_rsa_adnanafzal565 -o IdentitiesOnly=yes" git push origin main

-o IdentitiesOnly=yes” this will prevent SSH from trying other keys. So it will use this specific key only.


cp source destination

This will copy a file or folder from one folder to another. The source file/folder will remain, it will not be deleted.


mv source destination

This will move the file or folder from one folder to another. The source file/folder will be deleted after it is moved to a new location.


rm -rf file_or_folder

Above command will permanently remove a file or folder (no recycle bin). It will do it recursively, this is needed when you folders inside folders. It will not ask for confirmation, it will forcefully perform the action.


Below are the list of those important CLI commands discussed in this blog post along with some others too.

Important CLI commands

cd ~/.ssh
ssh-keygen -t ed25519 -C "support@adnan-tech.com" -f id_ed25519
ssh-keygen -t ed25519 -C "support@adnan-tech.com"
chmod 600 id_ed25519
cat id_ed25519.pub
GIT_SSH_COMMAND="ssh -i id_ed25519 -o IdentitiesOnly=yes" git pull origin master
GIT_SSH_COMMAND="ssh -i id_ed25519 -o IdentitiesOnly=yes" git push origin master
GIT_SSH_COMMAND="ssh -i id_ed25519 -o IdentitiesOnly=yes" git fetch origin
GIT_SSH_COMMAND="ssh -i id_ed25519 -o IdentitiesOnly=yes" git reset --hard origin/master
GIT_SSH_COMMAND="ssh -i id_ed25519 -o IdentitiesOnly=yes" git clean -fd
git config --global user.email "support@adnan-tech.com"
git config --global user.name "Adnan Afzal"
unzip file.zip -d file
cp source destination
mv source destination
rm -rf file_or_folder

Learn how you can manage an entire website using Git from here.