Skip to main content

How to use gdb in Ubuntu Terminal

Here's a practical, minimal guide for using GDB in Ubuntu terminal — from launching to setting breakpoints and navigating your code. 🧰 Step 1: Compile with Debug Symbols Use -g and disable optimizations ( -O0 preferred for debugging): bash Copy Edit g++ -g -O0 -o myprog myprog.cpp 🚀 Step 2: Launch GDB bash Copy Edit gdb ./myprog You'll see a (gdb) prompt. 🎯 Step 3: Set Breakpoints You can set breakpoints in three main ways : ✅ a. At a function gdb Copy Edit (gdb) break main ✅ b. At a specific file and line gdb Copy Edit (gdb) break myprog.cpp:42 ✅ c. At a method in a class gdb Copy Edit (gdb) break MyClass::doSomething If the symbol is mangled (C++), GDB usually demangles automatically, especially if compiled with -g . ▶️ Step 4: Run the Program gdb Copy Edit (gdb) run 🧭 Step 5: Navigate Command Meaning next or n Step over current line step or s Step into function call finish Run until current function returns continue or c Continue until...

Managing gpg2 keys in Ubuntu (more update to be done...[eg gpg2 key creation, etc]) [chatGpt tutorial/discussion]

 Query?

List all gpg2 keys in ubuntu:

To list all installed GPG keys that can be used for signing, you can run the following command:

bash
gpg2 --list-secret-keys --keyid-format LONG

This command will show all secret keys (private keys) available for signing, as well as their associated public keys. The output will display the key IDs, user IDs, and additional information about the keys.

Let me know if you need further assistance!

-----------------------------------------------------------------------

Query?

How to view keys in terminal?

To view GPG keys in the terminal, you can use the following commands based on whether you want to see public or private keys:

1. View Public Keys

To list all public keys, use:

bash
gpg2 --list-keys --keyid-format LONG

This will display all the public keys installed on your system, along with their key ID, user information, and validity.

2. View Private (Secret) Keys

To list all private (secret) keys, use:

bash
gpg2 --list-secret-keys --keyid-format LONG

This command will show all private keys available on your system. The output includes the key ID, user ID, and additional details like creation date.

3. Detailed Information about a Specific Key

To get detailed information about a specific key, use the following command:

bash
gpg2 --list-sigs YOUR_KEY_ID

Replace YOUR_KEY_ID with the specific key's ID or email address. This will show all the signatures on the key and additional metadata.

If you want to see the raw data of the key itself, you can use:

  • For public key:

    bash
    gpg2 --export --armor YOUR_KEY_ID
  • For private key:

    bash
    gpg2 --export-secret-keys --armor YOUR_KEY_ID

This will output the keys in ASCII format directly to the terminal.

-----------------------------------------------------------

Query?

How to export keys from one pc to another?

To export GPG keys from one PC to another, follow these steps:

1. Export Public Key

To export the public key (which is used for encryption and verification), run:

bash
gpg2 --export --armor YOUR_KEY_ID > public-key.asc

Replace YOUR_KEY_ID with the key ID you obtained from gpg2 --list-keys. This command will export the public key to a file named public-key.asc in ASCII format.

2. Export Private Key (if needed)

To export the private key (required for signing and decryption), use:

bash
gpg2 --export-secret-keys --armor YOUR_KEY_ID > private-key.asc

This will export your private key into the private-key.asc file in ASCII format.

Warning: Handle private keys carefully, as they grant full access to encrypted data and the ability to sign messages.

3. Transfer the Keys to the Other PC

Transfer the key files (public-key.asc and/or private-key.asc) to the destination PC. You can use a secure method like SSH, SCP, or a USB drive.

4. Import Keys on the Other PC

Once on the other PC, import the public and/or private keys using the following commands:

  • To import the public key:

    bash
    gpg2 --import public-key.asc
  • To import the private key:

    bash
    gpg2 --import private-key.asc

5. Trust the Imported Keys (Optional)

After importing, you might need to set the trust level of the keys. To do this, use:

bash
gpg2 --edit-key YOUR_KEY_ID

Once in the interactive session, type:

bash
trust

Then choose the appropriate trust level (e.g., "5" for ultimate trust) and save the changes.


That’s it! You should now have your GPG keys available on the other PC.

-----------------------------------------------------------

Query?

Upon edit I set trust, but showing validity unknown. In oricinal pc its showing both validity n trust as ultimate

When you import a GPG key on a new machine, the trust level does not carry over automatically, which is why you're seeing "validity unknown" on the new PC. Even though you may have set trust on the key, the GPG system requires you to explicitly mark the key as trusted.

Here's how you can fix the "validity unknown" issue by correctly setting the trust:

1. Edit the Key's Trust Level

You can manually set the key's trust to "ultimate" using the following steps:

bash
gpg2 --edit-key <keyid>

This will open the interactive gpg shell for that specific key.

2. Set Trust

Once in the interactive shell, type:

bash
trust

GPG will prompt you to choose a trust level. Select 5 for ultimate trust:

bash
Please decide how far you trust this user to correctly verify other users' keys. 1 = I don't know or won't say 2 = I do NOT trust 3 = I trust marginally 4 = I trust fully 5 = I trust ultimately

Choose 5 (ultimate), then type quit to save and exit the interactive session.

3. Refresh Keyring (Optional)

If you've set the trust level correctly but the validity is still showing as "unknown," you can refresh the keyring:

bash
gpg2 --check-trustdb

This will check and rebuild the trust database, which should update the key's validity status.

After this, the key should show both trust and validity as "ultimate," just like on your original PC.

==========================

Git signing notes:

gpg --list-secret-keys --keyid-format=long

git config --global user.signingkey <keyid>

To configure Git to sign all commits by default, enter the following command:

git config --global commit.gpgsign true

==================================

Comments

Popular posts from this blog

Ubuntu Notes: Set up autossh as systemd useful-reminder commands

 sudo vim /etc/systemd/system/permanentAutossh.service ======================================== [Unit] Description=Keeps a tunnel to myOciFreeNat open After=network-online.target [Service] User=<username> Environment="AUTOSSH_GATETIME=0" ExecStart=/usr/bin/autossh -M 0 -q -N -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -L 4322:127.0.0.1:5432 -i /<ssh_private_key_file_absolute_path> <username>@<ip_address> -p 22 [Install] WantedBy=multi-user.target ======================================== sudo systemctl daemon-reload sudo systemctl enable permanentAutossh sudo systemctl start permanentAutossh ================== sudo systemctl daemon-reload sudo systemctl restart permanentAutossh sudo systemctl status permanentAutossh ====================== sudo systemctl stop permanentAutossh sudo systemctl disable permanentAutossh sudo rm /etc/systemd/system/permanentAutossh.service

syslog cpp programming: learning using chatGcp

  Introduction to Syslog C++ August 27, 2024 This conversation may reflect the link creator’s personalized data, which isn’t shared and can meaningfully change how the model responds. You said: I am new to syslog in cpp programming n just starting. Can you teach me ChatGPT said: ChatGPT Sure! syslog is a standard for logging system messages in Unix-like operating systems. It provides a way to send log messages to the system log, which can then be collected and analyzed by various tools. Here's a basic guide to get you started with syslog in C++: 1. Include the Necessary Header To use syslog , you need to include the syslog.h header: cpp Copy code # include <syslog.h> 2. Open the Connection to syslog Before sending log messages, you need to open a connection to the syslog system. This is typically done at the start of your program: cpp Copy code openlog ( "your_program_name" , LOG_PID | LOG_CONS, LOG_USER); "your_program_name" : A string representing ...

Ubuntu - C++ Notes: Install & update boost c++ library from git (may contain some error in process mentioned below)

 Boost C++ Library Installation from git in ubuntu: 1. create a directory named boost in your desired location and go to that directory mkdir boost;cd boost; 2. clone boost recursively from git using command git clone --recursive https://github.com/boostorg/boost.git 3. cd boost; sudo ./bootstrap.sh; 4. sudo ./b2; 5. sudo ./b2 install; DONE! --------------------------- Boost C++ Library Update Verson from git in Ubuntu: 1. go to gitDownloads/boost directory cd gitDownloads/boost; 2. git pull; 3. git submodule update --recursive; 4. cd boost; sudo ./bootstrap.sh; 5. sudo ./b2; 6. sudo ./b2 install; DONE!