Thursday 19 September 2024

How to restrict or limit a new ubuntu user from accessing other folder?

1. add a new user

sudo adduser newuser


2. add user to sudo group

sudo usermod -aG sudo newuser


3. add user to ssh group

sudo vim /etc/ssh/sshd_config

>>AllowUsers newuser


4. add restriction to the new user (space sensitive)

sudo visudo -f /etc/sudoers.d/newuser

>>newuser ALL=(ALL) ALL, !sudoedit, !/usr/bin/su, !/bin/su, !/bin/bash, !/bin/sh, !/usr/bin/chmod, !/usr/bin/chown, !/usr/bin/docker, !/usr/bin/passwd, !/usr/sbin/visudo


5. check the new restriction

sudo visudo -c

If it is ok, you will the following message print out:

/etc/sudoers: parsed OK

/etc/sudoers.d/README: parsed OK

/etc/sudoers.d/newuser: parsed OK


6. apply folder restriction to current user folder
sudo chmod -R 700 /home/currentuser

7. reboot the machine and check the restriction
sudo reboot
cd /home/currentuser
sudo chmod -R 777 /home/currentuser
sudo docker ps

How to ssh or scp without password?

 

Method 1: Use SSH Key-Based Authentication

The most secure and recommended way is to set up SSH key-based authentication, which doesn't require you to include a password in the command.


1. Generate SSH Key Pair (if you don’t have one already):

    ssh-keygen -t rsa -b 4096

Save the key in the default location (~/.ssh/id_rsa).


2. Copy Public Key to the Remote Machine:

ssh-copy-id username@remote_host -p 22

Replace username and remote_host with your remote machine's username and IP address or hostname.

3. Run rsync without Password or ssh into another machine without Password:

rsync -avz /path/to/source/ username@remote_host:/path/to/destination/

ssh username@remote_host -p 22


4. Change folder permission on destination folder.

sudo chmod -R 777 destination_folder

Monday 22 July 2024

How to install ffmpeg offline using a static version?

Ref: https://johnvansickle.com/ffmpeg/

1. What is a static build and how do I install it?

static build is basically a binary with all the libs included inside the binary itself. There's no installation necessary in order to use a static binary, but you may want to place it in your shell's PATH to easily call it from the command line. Otherwise you can use the binary's absolute path. Here's a quick walkthrough:

Download the latest git build.

$ wget https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz

$ wget https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz.md5


With the build and the build's md5 hash downloaded you can check its integrity.

$ md5sum -c ffmpeg-git-amd64-static.tar.xz.md5
ffmpeg-git-amd64-static.tar.xz: OK


Unpack the build. Note: If you need to do this on Windows, use 7-Zip to unpack it. You may have to run it twice; once to uncompress and again to untar the directory.

$ tar xvf ffmpeg-git-amd64-static.tar.xz


Now I have the directory "ffmpeg-git-20180203-amd64-static".

$ ls ffmpeg-git-20180203-amd64-static
ffmpeg  ffprobe  GPLv3.txt  manpages  model  qt-faststart  readme.txt


Please read readme.txt! (hit "q" to exit out of "less")

$ less ffmpeg-git-20180203-amd64-static/readme.txt


Without any further steps I can start using ffmpeg with my relative path to the binary.

$ ./ffmpeg-git-20180203-amd64-static/ffmpeg
ffmpeg version N-89948-ge3d946b3f4-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 6.4.0 (Debian 6.4.0-11) 20171206
(snipped output to save space)


Or using the absolute path to the binary.

$ /home/john/ffmpeg-git-20180203-amd64-static/ffmpeg
ffmpeg version N-89948-ge3d946b3f4-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 6.4.0 (Debian 6.4.0-11) 20171206
(snipped output to save space)


To globally install it I need to move the binary into my shell's path. "PATH" is a variable in your environment set to a list of colon seperated directories the shell uses to locate binaries. Here's my system's path.

$ echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/john/.local/bin:/home/john/bin

Your output may look different than mine, but it will be a somewhat similar list of directories. When I run the command "ffmpeg", the shell will look in /usr/local/bin first and then the next directory to the right in above list until it's found. If there's not a binary named "ffmpeg" in any of the above directories the shell will return "ffmpeg: command not found".


Before moving the ffmpeg binary into the shell's path, check to see if an older version of ffmpeg is already installed.

$ whereis ffmpeg 
ffmpeg: /usr/bin/ffmpeg

This lists an older version of ffmpeg in /usr/bin installed via my package manager. I can either uninstall the older version or place the newer static ffmpeg binary in a path that's searched before /usr/bin. According to my shell's path that would be /usr/local/bin.


Move the static binaries ffmpeg and ffprobe into the shell's path.

$ sudo mv ffmpeg-git-20180203-amd64-static/ffmpeg ffmpeg-git-20180203-amd64-static/ffprobe /usr/local/bin/

$ whereis ffmpeg
ffmpeg: /usr/local/bin/ffmpeg

$ whereis ffprobe
ffprobe: /usr/local/bin/ffprobe



Now ffmpeg is globally installed and you're done!

$ ffmpeg
ffmpeg version N-89948-ge3d946b3f4-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 6.4.0 (Debian 6.4.0-11) 20171206
  (snipped output to save space)


Uninstall.

$ sudo rm /usr/local/bin/ffmpeg /usr/local/bin/ffprobe

Thursday 4 July 2024

How to encode and decode character into ascii code?

 https://www.w3schools.com/tags/ref_urlencode.ASP


Character From Windows-1252 From UTF-8
space %20 %20
! %21 %21
" %22 %22
# %23 %23
$ %24 %24
% %25 %25
& %26 %26
' %27 %27
( %28 %28
) %29 %29
* %2A %2A
+ %2B %2B
, %2C %2C
- %2D %2D
. %2E %2E
/ %2F %2F
0 %30 %30
1 %31 %31
2 %32 %32
3 %33 %33
4 %34 %34
5 %35 %35
6 %36 %36
7 %37 %37
8 %38 %38
9 %39 %39
: %3A %3A
; %3B %3B
< %3C %3C
= %3D %3D
> %3E %3E
? %3F %3F
@ %40 %40

Thursday 4 April 2024

How to print out ubuntu specs? Neofetch

sudo apt install neofetch -y

neofetch

neofetch --off (without any logo printed)

Monday 1 April 2024

How to push the opencv result into a rtsp link?

1. download the rtsp server from this link and run it before step2 below, 

https://github.com/bluenviron/mediamtx/releases/download/v1.6.0/mediamtx_v1.6.0_linux_amd64.tar.gz


2. create an example main.cpp using the following code:-

#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/video.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc.hpp>

using namespace cv;
using namespace std;

int main()
{

    //VideoWriter writer("appsrc ! videoconvert ! video/x-raw,format=I420 ! x264enc speed-preset=ultrafast bitrate=600 key-int-max=30 ! video/x-h264,profile=baseline ! rtspclientsink location=rtsp://localhost:8554/mystream",

    VideoWriter writer("appsrc ! videoconvert ! video/x-raw,format=I420 ! x264enc tune=zerolatency byte-stream=true threads=4 ! h264parse ! rtspclientsink location=rtsp://localhost:8554/mystream",
0,
15,
Size(1920, 1080),
true);

    VideoCapture cap("../sample_1080p_h265.mp4");
    //VideoCapture cap("rtsp://192.168.80.203");

    for (;;)
    {
        if (!cap.isOpened()) {
            cout << "Video Capture Fail" << endl;
            break;
        }

        Mat img;
        cap >> img;
        std::cout << "img shape: " << img.rows << ", " << img.cols << std::endl;

        //namedWindow("Display window", WINDOW_AUTOSIZE);// Create a window for display.
        //imshow("Display window", img);
        //waitKey(1);

        writer.write(img);
    }
}

3. create the CMakeLists.txt and build the program


cmake_minimum_required(VERSION 2.8)
project( main )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( main main.cpp )
target_link_libraries( main ${OpenCV_LIBS} )

4. view the live result using vlc, rtsp://localhost:8554/mystream