Some Basic Linux Commands¶
SSH or Remote Use¶
To connect to another system from your current machine, you use
My username I use is
jpartain89, so :
It will ask for your users password, if your ssh keys are not setup.
To generate SSH keys:
ssh-keygen -t rsa -b 2096
It will ask for location, hit
enter for the standard default location.
If you want a password on this key, for extra extra security, you can type that in with the next option. Or, for no passphrase, just hit
enter again for confirmation, or retype the password if you wanted one.
Then, it’ll output the key ‘randomart’ image, which doesn’t mean much. But, the default location is
~/.ssh. It’ll tell you where.
SSH Key Location¶
The private key is like your front door key on your keyring. Only you have it. The public key is like the tumblers. Anyone can see it, but cannot access without your private key.
SSH-Copy-ID or Sending Your Public Key¶
The public key is copied to the servers that you want to access without password input. There is a program to do that.
ssh-copy-id. On macOS,
brew install ssh-copy-id. Linux should already have it installed.
To send your public keys, you use
ssh-copy-id is the program, then
your username @ the ip address of the computer. It’ll ask for your password, then copy the keys. Then,
ssh firstname.lastname@example.org and it should no longer ask for your password!
Restarting the Machine¶
sudo shutdown -r now
shutdown- obviously is the shutdown program
-r- the -r flag is for restarting.
now- tells it to do it now, rather than wait. You can set times before it shutsdown or restarts, in case other users are on the machine.
Updating the Apps¶
sudo apt-get update && sudo apt-get upgrade -y
apt-getis the installing program that debian/ubuntu uses. Its a super simple means of installing in the terminal.
update- obviously runs an update. This means it downloads a list or a cache of the version numbers and states of the programs in apt-get’s lists.
run this stuff after the last one succeeds successfully
upgrade- this actually takes the programs installed by apt-get, and upgrades them.
-y- basically means
yes, do this without asking like normal
exec 1> >(logger -s -t "$(basename "$0")") 2>&1
Been looking for a way to pipe your entire bash script into a log file, syslog, journald, or whatever? The above line does it super simply!!
This was a line I had found a few years back, started learning ansible, and lost this nugget of knowledge, and recenlty found it once again (but lost the website I found it from… Sorry!)
What does it do?¶
exec: this line tells bash “you are to run everything”
1> >(this sets up piping
stdout) through to whats inside the parenthesis
logger -s -t "$(basename "$0")")the
loggerprogram is a means of piping output into your systems
rsyslogor what have you.
basenameadds the file/scripts name onto the syslog entry.
2>&1is for piping
This information was wonderfully pulled from UrbanAutomation’s website.