Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
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.

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
How to get default gateway IP address?

ip route | grep default


The output would be something like below:

default via 192.168.1.1 dev eth0 onlink


NOTE: it can be different on your system

#linux #sysadmin #ip #route #default_gateway
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 O
S. 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:

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 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
Do you need a full-featured open source mail server?

Postal is a complete and fully featured mail server for use by websites & web servers. Think Sendgrid, Mailgun or Postmark but open source and ready for you to run on your own servers. Postal was developed by aTech Media to serve its own mail processing requirements and we have since decided that it should be released as an open source project for the community.

Read more about it on github page:
- https://github.com/atech/postal

#github #mailserver #mail #mailgun #sendgrid #postmark #postal #open_source
How a programmer download from Spotify? (In case you cannot purchase the song and download them from IR like me)

spotdl is one of the great number one python 3 packages that downloads a song or playlist on your system.

In order to download a song copy the music link and:

spotdl --song https://open.spotify.com/track/2DGa7iaidT5s0qnINlwMjJ


Or in case you have a playlist link:

$ spotdl --playlist https://open.spotify.com/user/nocopyrightsounds/playlist/7sZbq8QGyMnhKPcLJvCUFD
INFO: Writing 62 tracks to ncs-releases.txt
$ spotdl --list ncs-releases.txt


To read installation and more command options:

- https://github.com/ritiek/spotify-downloader

#python3 #spotdl #spotify #github
Visual Studio Live Share

Real-time collaborative development can be done using live share plugin. Coders can work simultanously o nthe same file without an interruption:

- https://visualstudio.microsoft.com/services/live-share/

#IDE #microsoft #liveshare #plugin #visualstudio
One of the methods to document your API is APIDOC. It uses annotation in variety of languages like Python, PHP, JS, etc. At the below code block you can see an example in Python:

"""
@api {get} /user/:id Request User information
@apiName GetUser
@apiGroup User

@apiParam {Number} id Users unique ID.

@apiSuccess {String} firstname Firstname of the User.
@apiSuccess {String} lastname Lastname of the User.
"""


To read more about the APIDOC itself and the installation process head over to link below:

- http://apidocjs.com/

#javascript #js #python #apidoc #apidocjs #api #documentation #rest #annotation
Bamilo has reached its end!

The ecommerce website Bamilo which tried hard to combat with Digikala has closed down. The domain now redirects to snapp market:

- https://www.bamilo.com/

#bamilo #digikala #failure #ecommerce #snapp
DO NOT USE UWSGI multi-threaded mode with alpine image!

I've been stuck on this issue for a couple of days as our service returned 503 Gateway timeout while our server load was totally ok around 1.0 (1m load average). So our load test got failed at the be beginning of the test! We found out it is related to docker base image of python alpine. Use python slim image instead. Or in case you have many changes you can stick with alpine and change thread to 1 in uswgi configuration file.


#docker #alpine #uwsgi #python #slim #respawn
Do you log a lot like me in your Python modules? If so, you had the same problem to always find the first occurence of a log after time, filename, etc. Let's clarify this with a sample log:

[2012-10-02 application.py:1 _get()] DEBUG: this is a log content
[2012-10-02 db.py:1005 _fetch_all_info()] INFO: this is a log content


You can see that both have the same log content but it's hard to follow cause of length of file name, line number and function name. To format this better we can have space padding in formatters. spaces are identified by `s. Now lets see the same log, but this time with space padding.

The formatter is as below:

[%(asctime)s %(filename)15s:%(lineno)4s %(funcName)20s()] %(levelname)s %(message)s


NOTE: this is not the exact formatter for the above log, it is for demonstration!


Now the output will something like below:

[2012-10-02   application.py:    1               _get()] DEBUG: this is a log content
[2012-10-02 db.py: 1005 _fetch_all_info()] DEBUG: this is a log content


You can see that log content is so much easier to follow by using space padding. It may not be obvious on telegram with small devices. So try it your self :)))

#python #logging #log #logger #formatter #log_formatter #space_padding #padding
How does kubernetes scheduler work? Stripe engineer Julia Evans has written a delightfully clear explanation of how sched‐
uling works in Kubernetes.

https://jvns.ca/blog/2017/07/27/how-does-the-kubernetes-scheduler-work/


#containerization #kubernetes #scheduler #pods #kubectl