Why I implement this application.
Why I implement this application.
coldnew@gentoo ~ $ ssh coldnew@192.168.20.100 The authenticity of host '192.168.20.100 (192.168.20.100)' can't be established. ECDSA key fingerprint is SHA256:izC+HeDEm/u1FcCzpM+aBgpbuGlrGD1HkMnwLVkS+ac. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.20.100' (ECDSA) to the list of known hosts. Password:
You can use ssh-copy-id to make ssh without password
coldnew@gentoo ~ $ ssh-copy-id ~/.ssh/id_rsa.pub coldnew@192.168.20.100 Password:
Now it's no need to type any password to login
coldnew@gentoo ~ $ ssh coldnew@192.168.20.100 Warning: Permanently added '192.168.20.100' (ECDSA) to the list of known hosts. coldnew@pc ~ $
What if we don't trust Google ?
Let's talk about telegram-authenticator
Client is open source, but server isn't
239551761:AAFRfD7iN-YTC1o5od8y0IMnFbg-fWdkG4I
And you'll know how to write a bot
All list in this page
https://api.telegram.org/bot${TOKEN}/getUpdates
239551761:AAFRfD7iN-YTC1o5od8y0IMnFbg-fWdkG4I
https://api.telegram.org/bot239551761:AAFRfD7iN-YTC1o5od8y0IMnFbg-fWdkG4I/getUpdates
{ "ok":true, "result":[ { "update_id":556578430, "message":{ "message_id":2, "from":{ "id":81660412, "first_name":"Yen-Chin", "last_name":"Lee", "username":"coldnew" }, "chat":{ "id":81660412, "first_name":"Yen-Chin", "last_name":"Lee", "username":"coldnew", "type":"private" }, "date":1473738006, "text":"test" } }, ] }
8166042{"update_id":556578430, "message":{ "message_id":2, "from":{ "id":81660412, "first_name":"Yen-Chin", "last_name":"Lee", "username":"coldnew" }, "chat":{ "id":81660412, "first_name":"Yen-Chin", "last_name":"Lee", "username":"coldnew", "type":"private" }, "date":1473738006, "text":"test" } }
https://api.telegram.org/bot${TOKEN}/sendMessage
https://api.telegram.org/bot239551761:AAFRfD7iN-YTC1o5od8y0IMnFbg-fWdkG4I/sendMessage
{"chat_id": "81660412", "text": "Hello telegram bot"}
curl -s \ -X POST \ https://api.telegram.org/bot239551761:AAFRfD7iN-YTC1o5od8y0IMnFbg-fWdkG4I/sendMessage \ -d text="Hello telegram bot" \ -d chat_id=81660412
Use for user authentication in any modern linux distribution
#include <stdio.h> #include <stdlib.h> #include <syslog.h> #include <security/pam_modules.h> #include <security/pam_ext.h> PAM_EXTERN int pam_sm_authenticate(pam_handle_t* pamh, int flags, int argc, char const** argv) { pam_info(pamh, "Hello there!!"); return PAM_IGNORE; } PAM_EXTERN int pam_sm_setcred(pam_handle_t* pamh, int flags, int argc, char const** argv) { return PAM_SUCCESS; }
gcc pam_hello.c -fPIC -lpam -shared -o pam_hello.so
In my system, it's /lib/security
sudo mv pam_hello.so /lib/security/
Modify /etc/pam.d/sshd
auth required pam_hello.so
Modify /etc/ssh/sshd_config
ChallengeResponseAuthentication yes
Remember to restart sshd first
sudo systemctl rstart sshd
Test ssh login
coldnew@pc ~ $ ssh coldnew@192.168.20.100 Password: Hello there!! coldnew@gentoo ~ $
telegram-authenticator
CMove the lib to /lib/security
sudo mv pam_telegram_authenticator.so /lib/security/
Modify /etc/pam.d/sshd
auth required pam_telegram_authenticator.so
Modify /etc/ssh/sshd_config
ChallengeResponseAuthentication yes
coldnew@gentoo ~ $ telegram-authenticator Please enter your telegram bot token: 239551761:AAFRfD7iN-YTC1o5od8y0IMnFbg-fWdkG4I Please type '/start' to your telegram bot Waiting for user type '/start' in telegram bot channel Find chat_id: 81660412 Do you want to write setting to your config? (y/n) y
A little guide on json-c
{ "ok":true, "result":[ { "update_id":556578430, "message":{ "message_id":2, "chat":{ "id":81660412 } "text":"test" }}]}
json_object *root = json_tokener_parse(DATA); json_object *body; json_object_object_get_ex(root, "result", &body); // print it printf("result: %s\n", json_object_to_json_string(body));
{ "result":[ {"message":{ "message_id":2, "chat":{ "id":81660412 } "text":"test" }}]}
json_object *root = json_tokener_parse(DATA); json_object *body; json_object_object_get_ex(root, "result", &body); int arraylen = json_object_array_length(body); json_object *jvalue; for (int i = 0; i < arraylen; i++) { jvalue = json_object_array_get_idx(body, i); struct json_object *jchat; json_object_object_get_ex(jmessage, "chat", &jchat); struct json_object *jchat_id; json_object_object_get_ex(jchat, "id", &jchat_id); }
Thank You