Does that happen for you too, to
Let's say you are in a long path like
#linux #cd
CD
into a wrong directory and need to get back to the previous directory?Let's say you are in a long path like
/mnt/new_volume/backup/files/archive
, now you switch to home of your directory. In order to get back to the previous directory, you just need to issue the below command:cd -
#linux #cd
If you forget to pull your projects from git in a regular interval and many users working on the same projects, then there is a solution for you!
Create a bash script file as follow and make it executable by
Now as a final step, put it in your crontab:
#linux #git #pull #cronjob #crontab #cron #bash
Create a bash script file as follow and make it executable by
chmod +x puller.sh
:puller.sh
file content:#!/bin/bash
echo 'Iterating over folders...'
for dir in *
do
test -d "$dir" && {
cd ${dir}
echo "git pull $dir"
git pull
cd ".."
} || {
echo "------> $dir is not a directory <-------"
}
done
NOTE:
this file should reside in your folder's project root. In my case it is in /Your/Projects/Folder
.Now as a final step, put it in your crontab:
10 * * * * bash -c "cd /Your/Projects/Folder; bash puller.sh >> /var/log/git_pull_output.log"
#linux #git #pull #cronjob #crontab #cron #bash
We have talked before about how to get current month using the below line of code:
It prints out 01, 02, etc.
As per the
So you can remove leading zero by hyphen as below:
It prints out 1, 2, etc.
#linux #bash #date
echo $(date +%m)
It prints out 01, 02, etc.
As per the
GNU date manpage
:By default, date pads numeric fields with zeroes. The following
optional flags may follow '%':
- (hyphen) do not pad the field
So you can remove leading zero by hyphen as below:
echo $(date +%-m)
It prints out 1, 2, etc.
#linux #bash #date
https://xiaoxiaoke.wordpress.com/2015/10/06/changing-java-security-restriction-for-network-connect-error-issue-in-kvm/
#linux #devops #sysadmin #kvm #hp
#linux #devops #sysadmin #kvm #hp
Ke Xu | Geek World
Changing java security restriction for “Network connect error” issue in KVM
I am using KVM to manage the servers in a rack. When launching the session jnlp files with javaws, I saw the “Network connect error” message. This is due to the default java security re…
How to SSH login without password?
You want to use Linux and OpenSSH to automate your tasks. Therefore you need an automatic login from host A / user a to Host B / user b. You don't want to enter any passwords, because you want to call ssh from a within a shell script.
First log in on A as user a and generate a pair of authentication keys. Do not enter a passphrase:
Now use ssh to create a directory
Finally append a's new public key to
From now on you can log into B as b from A as a without password:
#linux #sysadmin #ssh #password_less #ssh_login
You want to use Linux and OpenSSH to automate your tasks. Therefore you need an automatic login from host A / user a to Host B / user b. You don't want to enter any passwords, because you want to call ssh from a within a shell script.
How to do it?
First log in on A as user a and generate a pair of authentication keys. Do not enter a passphrase:
a@A:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa):
Created directory '/home/a/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/a/.ssh/id_rsa.
Your public key has been saved in /home/a/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A
Now use ssh to create a directory
~/.ssh
as user b on B. (The directory may already exist, which is fine):a@A:~> ssh b@B mkdir -p .ssh
b@B's password:
Finally append a's new public key to
b@B:.ssh/authorized_keys
and enter b's password one last time:a@A:~> cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'
b@B's password:
From now on you can log into B as b from A as a without password:
a@A:~> ssh b@B
#linux #sysadmin #ssh #password_less #ssh_login
Virt-builder
is a tool for quickly building new virtual machines. You can build a variety of VMs for local or cloud use, usually within a few minutes or less. Virt-builder
also has many ways to customize these VMs. Everything is run from the command line and nothing requires root privileges, so automation and scripting is simple.To see available virtual machines:
virt-builder --list
Sample command to create a
debian-9
image:sudo virt-builder debian-9 --size=50G --hostname prod.example.com --network --install network-manager --root-password password:YOUR_PASS
The above command creates a debian 9 image with disk size of 50GB and sets the hostname to
prod.example.com
. --network
enables the networking on guest and --install
installs packages on the target OS. The last parameter sets the root password to
YOUR_PASS
.To read more about the axtra parameters:
- http://libguestfs.org/virt-builder.1.html
#linux #sysadmin #virt_builder #debian #image
You can login to a server without entering a password by a simple command as below:
By issuing the above command it puts your public key content on server
#linux #sysadmin #ssh #passwordless_login #ssh_copy_id #authorized_keys #public_key
ssh-copy-id USERNAME@YOUR_HOST_IP -p 22
By issuing the above command it puts your public key content on server
~/.ssh/authorized_keys
and prompts you to enter the password. You are all done by this.#linux #sysadmin #ssh #passwordless_login #ssh_copy_id #authorized_keys #public_key
How I store & manage passwords in Linux for servers and other credentials? gopass
Password management should be simple and follow Unix philosophy. With
- https://github.com/gopasspw/gopass
#unix #linux #sysadmin #pass #gopass #password_management #golang #github
Password management should be simple and follow Unix philosophy. With
pass
, each secret lives inside of a gpg
encrypted file whose filename is the title of the website or resource that requires the secret. These encrypted files may be organized into meaningful folder hierarchies, copied from computer to computer, and, in general, manipulated using standard command line file management utilities. gopass
is a rewrite of the pass
password manager in Go
with the aim of making it cross-platform and adding additional features. Our target audience are professional developers and sysadmins
(and especially teams of those) who are well versed with a command line interface. One explicit goal for this project is to make it more approachable to non-technical users. We go by the UNIX philosophy and try to do one thing and do it well, providing a stellar user experience and a sane, simple interface:- https://github.com/gopasspw/gopass
#unix #linux #sysadmin #pass #gopass #password_management #golang #github
GitHub
GitHub - gopasspw/gopass: The slightly more awesome standard unix password manager for teams
The slightly more awesome standard unix password manager for teams - gopasspw/gopass
https://superuser.com/questions/453988/whats-the-difference-between-su-with-and-without-hyphen
#linux #su
#linux #su
Super User
What's the difference between "su" with and without hyphen?
I'm quite new to Linux terminal and I'm not quite sure what the difference between su with a hyphen and su without a hyphen is, for example: su - username vs. su username.
I looked into the documen...
I looked into the documen...
https://stackoverflow.com/questions/13032409/ssh-remote-variable-assignment
#linux #sysadmin #ssh #local_variable #variable_expansion #bashrc #export
#linux #sysadmin #ssh #local_variable #variable_expansion #bashrc #export
Stack Overflow
ssh remote variable assignment?
The following does not work for me:
ssh user@remote.server "k=5; echo $k;"
it just returns an empty line.
How can I assign a variable on a remote session (ssh)?
Note: My question is not about ...
ssh user@remote.server "k=5; echo $k;"
it just returns an empty line.
How can I assign a variable on a remote session (ssh)?
Note: My question is not about ...
In order to enable bash completion in Kubernetes you can usee the below command in linux bash:
Now to test this enter the below command and you should see the completion:
It should be expanded to
#linux #bash #shell #kubernetes #kubectl
source <(kubectl completion bash)
Now to test this enter the below command and you should see the completion:
kubectl cl<TAB>
It should be expanded to
kubectl cluster-info
.#linux #bash #shell #kubernetes #kubectl
Create a linux SWAP file:
https://linuxize.com/post/create-a-linux-swap-file/
#linux #swap #swapfile #swappiness #swapon #mkswap
https://linuxize.com/post/create-a-linux-swap-file/
#linux #swap #swapfile #swappiness #swapon #mkswap
Linuxize
Create a Linux Swap File
Swap is a space on a disk that is used when the amount of physical RAM memory is full. When a Linux system runs out of RAM, inactive pages are moved from the RAM to the swap space.
In
you want to install network tools (like ping) you need to install
You can squash your image size even further by some tips. When you install a package, linux distros first download the package and put it in a cache folder. In
To tell the OS to delete the cache after installation you can provide
There are some package like
y using
Great job guys! You have reduced your alpine docker images so much :)
#docker #linux #alpine #apk #virtual #no_cache #apk_del #apk_add
Dockerfile`s some people in the community use `alpine
base image in order to reduce docker image size. apk
is its package management tool that can be used to install OS packages. So for example ifyou want to install network tools (like ping) you need to install
netcat-openbsd
:apk add netcat-openbsd
You can squash your image size even further by some tips. When you install a package, linux distros first download the package and put it in a cache folder. In
Alpine
it is located in /var/cache/apk
.To tell the OS to delete the cache after installation you can provide
--no-cache
option to it:apk add --no-cache netcat-openbsd
There are some package like
g++
or git
that is needed on installation of some other packages. After installation those packages is useless and just increase image size. You can remove those packages by using
--virtual
command:apk add --no-cache --virtual .build-deps g++ \
&& # do you stuff here \
&& apk del .build-deps
Great job guys! You have reduced your alpine docker images so much :)
#docker #linux #alpine #apk #virtual #no_cache #apk_del #apk_add
pdsh
: a high performance, parallel remote shell utility. Pdsh is a multithreaded remote shell client which executes commands on multiple remote hosts in parallel. Pdsh can use several different remote shell services, including standard "rsh", Kerberos IV, and ssh.To see more about it head over to:
- https://github.com/grondo/pdsh
#linux #shell #pdsh #shell
GitHub
GitHub - grondo/pdsh: A high performance, parallel remote shell utility
A high performance, parallel remote shell utility. Contribute to grondo/pdsh development by creating an account on GitHub.
How to copy a file in the same path with a different name?
Well you just need to use curly braces, {}, to make it happen:
What you usually MIGHT do:
You can take the smart path btw:
NOTE: if suffix of both files are different you can put that inside of curly braces too.
#linux #sysadmin #cp #copy #trick
Well you just need to use curly braces, {}, to make it happen:
What you usually MIGHT do:
cp /usr/local/share/lib/sample.conf /usr/local/share/lib/settings.conf
You can take the smart path btw:
cp /usr/local/share/lib/{sample,settings}.conf
NOTE: if suffix of both files are different you can put that inside of curly braces too.
#linux #sysadmin #cp #copy #trick
https://www.digitalocean.com/community/tutorials/using-grep-regular-expressions-to-search-for-text-patterns-in-linux
#linux #grep #regex
#linux #grep #regex
Digitalocean
Mastering grep with Regular Expressions: Guide for Efficient Text Search | DigitalOcean
Learn how to use grep with regular expressions to search, filter, and process text in Linux and Unix systems. This guide covers syntax, practical use cases, …