Posts

Showing posts with the label Linux

Adding Password To .ssh/config

Answer : Solution 1: No, There is no method to specify or provide on the command line the password in a non-interactive manner for ssh authentication using a openssh built-in mechanism. At least not one what I know of. You could hardcode your password into expect script but it is not a good solution either. You definitely would want to use keypairs for passwordless authentication as Michael stated, in the end private key is pretty much a big password in the file. Solution 2: To avoid the string of comments: Yes, this is insecure (not even arguably insecure). I would strongly recommend you only do it in a lab situation on an isolated network or a similiar situation that does not involve production servers or potentientially production server without a full reset/format. I wanted to set this up as I don't think my 2950 switch supports private/public keys and I hope at some point to get that knowledge, but I am not there yet. Using an alias and sshpass this can be acc...

Can I Use Ufw To Setup A Port Forward?

Answer : Solution 1: Let's say you want to forward requests going to 80 to a server listening on port 8080. Note that you will need to make sure port 8080 is allowed, otherwise ufw will block the requests that are redirected to 8080. sudo ufw allow 8080/tcp There are no ufw commands for setting up the port forwards, so it must be done via configuraton files. Add the lines below to /etc/ufw/before.rules , before the filter section, right at the top of the file: *nat :PREROUTING ACCEPT [0:0] -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080 COMMIT Then restart and enable ufw to start on boot: sudo ufw enable Solution 2: Since ufw 0.34 ufw supports forward rules. example: sudo ufw route allow in on eth0 out on eth1 to 10.0.0.0/8 port 8080 from 192.168.0.0/16 port 80 You also need to make sure you have the sysctl net.ipv4.ip_forward enabled. For most distributions, that's done by editing /etc/sysctl.conf and running sysctl -p or rebooting....

Can't Add Perf Probe For C++ Methods

Answer : As a workaround you can get the method address with objdump and perf probe will accept it. $ perf probe -x /path/file '0x643f30' Added new event: probe_libfile:abs_643f30 (on 0x643f30 in /path/file) You can now use it in all perf tools, such as: perf record -e probe_libfile:abs_643f30 -aR sleep 1 Do note that perf probe expects an offset from the file, and objdump and readelf return the address after adjusting for the loading address. For -pie executable, where the loading address is 0, the addresses will be the same. For non -pie executables you can get the loading address by looking at the output of readelf -l /path/file and searching for the offset 0x000000 and looking at what VirtAddr it points to, then subtract that number from the symbol address that you get from objdump --syms or readelf --syms . It will usually be 0x400000

Can I Boot Linux From A VHD?

Answer : yes, We just released a sample Linux VHD that you can boot any computer. You can find more info here: Download and boot your physical PC, also runs as vm - http://www.vmlite.com/index.php/forums/17-vboot/1864-linux-vhd-boot-available-download-and-boot-your-physical-pc-also-runs-as-vm 1 Linux as Real Appliance With VBoot for Linux, you can pre-install and pre-configure Linux OS and its applications, then distribute the resulting virtual disk file in VHD format. The vhd can boot a real computer, with configuration and apps instantly available. This way, operating systems are truly manageable, as simple as files. We call such a Linux VHD to be a real appliance, in the sense that it boots physical computers. It's very easy to setup and boot a computer with a vhd file. You download the vhd file, drop it to Windows or Linux file system, then configure the boot loader, and reboot the computer. 2 Linux as Virtual Appliance The exact same vhd file also runs as a vi...

A Command To Get The Sync Status Of A Dropbox File

Answer : Use filestatus : dropbox filestatus /path/to/file For more help see: dropbox help

Change Default DNS Server In Arch Linux

Answer : Arch Wiki explains: either use a resolv.conf.head file, or write-protect /etc/resolv.conf . The file /etc/resolv.conf generally should not be edited by hand. Most linux systems use a program called resolvconf that will automatically generate /etc/resolv.conf every time you connect to the LAN (as the post describes). Instead, you want to edit the file /etc/resolvconf.conf . Check man resolvconf for more information.

#!/bin/sh Vs #!/bin/bash For Maximum Portability

Answer : Solution 1: There are roughly four levels of portability for shell scripts (as far as the shebang line is concerned): Most portable: use a #!/bin/sh shebang and use only the basic shell syntax specified in the POSIX standard. This should work on pretty much any POSIX/unix/linux system. (Well, except Solaris 10 and earlier which had the real legacy Bourne shell, predating POSIX so non compliant, as /bin/sh .) Second most portable: use a #!/bin/bash (or #!/usr/bin/env bash ) shebang line, and stick to bash v3 features. This'll work on any system that has bash (in the expected location). Third most portable: use a #!/bin/bash (or #!/usr/bin/env bash ) shebang line, and use bash v4 features. This'll fail on any system that has bash v3 (e.g. macOS, which has to use it for licensing reasons). Least portable: use a #!/bin/sh shebang and use bash extensions to the POSIX shell syntax. This will fail on any system that has something other than bash for /bin/sh (su...

C: Linux Command Executed By Popen() Function Not Showing Results

Answer : Since the output is going to stderr you need to redirect stderr like so: FILE* file = popen("ntpdate 2>&1", "r"); this will redirect stderr to stdout and so you will see output from both. Second issue fscanf will stop at the first space so you can replace with fgets : fgets(buffer, 100, file); As Shafik Yaghmour correctly diagnosed, the output you see from ntpdate is written (correctly) to its standard error, which is the same as your programs standard error. To get the error messages sent down the pipe, use: FILE *file = popen("ntpdate 2>&1", "r"); That sends the standard error output from ntpdate to the standard output of the command, which is the pipe you're reading from. Of course, it looks like using ntpdate isn't going to work well until you've configured something.

Can't Install Kali Linux From USB, Fails To Find CD-ROM Drive

Answer : You could resolve the error by repeating the steps : Run the installer. Open a shell ( ALT + F2 ). Create the directory cdrom directly on the root of the file system: mkdir /cdrom Note : If you got problems making the directory /cdrom, disable the CD-rom player in BIOS or disconnect the cable Mount the USB as if it is a CD-ROM: mount -t vfat /dev/sdb1 /cdrom Where sdb1 is your USB device. You could carry on installation now After executing mount -t vfat /dev/sdb1 /cdrom , cd into the /cdrom directory and do an ls to see if the files are there. Then press ALT - F1 to go back, continue and re-select "detect CDROM" Source :ubuntu and debian Another layman solution was : when the Window shows CDROM couldn't be mounted , Unplug your USB from system and re insert it wait for mount/ detection (usb LED glow) Hit Continue You could do what I did. Hit escape, type install, hit enter, skip CD drive. If you ...

Boot Ubuntu 16.04 Into Command Line / Do Not Start GUI

Answer : You could disable the display manager service with systemctl . For example if your display manager is lightdm then run: sudo systemctl disable lightdm.service This will prevent the service from starting at boot. Edit : I forgot to mention how to start the GUI. It is as simple as starting the systemd service: sudo systemctl start lightdm.service Instead of text use runlevel 3 : GRUB_CMDLINE_LINUX="3" # To remove all the fancy graphics you need to get rid of `splash`. GRUB_CMDLINE_LINUX_DEFAULT=”quiet” # Uncomment to disable graphical terminal (grub-pc only) GRUB_TERMINAL=console Then update-grub and reboot. But you really only need GRUB_CMDLINE_LINUX="3" . For quick test hit ESC during booting to get into the grub boot menu. Then press e and find the line which specifies kernel and add 3 at the end: linux /vmlinuz root=/dev/mapper/ubuntu ro 3 Boot it with CTRL + x Ideally I also want to be able to start GUI by typ...

Android Studio 3.2.1 - Cannot Sync Project With Gradle Files: Argument For @NotNull Parameter 'message' Of ... Must Not Be Null

Answer : Ok, I was finally able to figure out the reason. The problem was, that my project folder resided on a different hard disk partition, than my home folder. The folder containing my android projects was linked to my home folder with a symbolic link. I can't tell whether its the symbolic link, or the other partition, that is causing the problem. I haven't checked that. Maybe it works if you have it on the same partition but linked with a symbolic link. Maybe it works when used on another partition without symbolic links. But for anyone experiencing this problem -> Check if one of these might be your cause as well. Some extra information: My android project folder resided on a hard disk partition formatted with ZFS. I saw a version of this with just now on Android Studio 3.4: the only error message I saw in the IDE was that Gradle sync failed, but in idea.log there was a NullPointerException and its traceback originated at com.intellij.openapi.extensions.Exte...

"apt-get Update" Fails? (Kali Linux With Virtual Box)

Answer : The solution is to change mirror in sources.list file. For some reason the default mirror is not working. There are several mirrors of the Kali Linux repository server, all of which are spread over the world. Each time you interact with the repository, by default it will automatically use the mirror that is closest to you based on your geoip location (idea being, this will give you the best speed due to less latency). However, you can manually force kali to use a certain/different mirror rather than the one that is nearest you. Go to http://http.kali.org/README.mirrorlist where you will have a list of mirrors to chose from. First backup your current source file mv /etc/apt/sources.list /etc/apt/sources.list.backup Then create a new sources.list file vim /etc/apt/sources.list and enter new mirror. For example, old sources.list file was deb http://http.kali.org/kali kali-rolling main contrib non-free The new sources.list file can be deb http://archiv...

Can Scp Copy Directories Recursively?

Answer : Solution 1: Yup, use -r : scp -rp sourcedirectory user@dest:/path -r means recursive -p preserves modification times, access times, and modes from the original file. Note: This creates the sourcedirectory inside /path thus the files will be in /path/sourcedirectory Solution 2: While the previous answers are technically correct, you should also consider using rsync instead. rsync compares the data on the sending and receiving sides with a diff mechanism so it doesn't have to resend data that was already previously sent. If you are going to copy something to a remote machine more than once, use rsync . Actually, it's good to use rsync every time because it has more controls for things like copying file permissions and ownership and excluding certain files or directories. In general: $ rsync -av /local/dir/ server:/remote/dir/ will synchronize a local directory with a remote directory. If you run it a second time and the contents of the loca...

Changing Root Password Does Not Change Sudo Password

Answer : You're changing root's password. sudo wants your user's password. To change it, try plain passwd , without arguments or running it through sudo . Alternately, you can issue: $ sudo passwd <your username> The password you use for sudo is the password of your own account, not the root account. sudo is used to grant you access to commands that need to be executed as root without giving you root access directly. To change your own password, use passwd without sudo.

Cannot Kill Python Script With Ctrl-C

Answer : Ctrl + C terminates the main thread, but because your threads aren't in daemon mode, they keep running, and that keeps the process alive. We can make them daemons: f = FirstThread() f.daemon = True f.start() s = SecondThread() s.daemon = True s.start() But then there's another problem - once the main thread has started your threads, there's nothing else for it to do. So it exits, and the threads are destroyed instantly. So let's keep the main thread alive: import time while True: time.sleep(1) Now it will keep print 'first' and 'second' until you hit Ctrl + C . Edit: as commenters have pointed out, the daemon threads may not get a chance to clean up things like temporary files. If you need that, then catch the KeyboardInterrupt on the main thread and have it co-ordinate cleanup and shutdown. But in many cases, letting daemon threads die suddenly is probably good enough. KeyboardInterrupt and signals are only seen by the proc...

Can Linux Cat Command Be Used For Writing Text To File?

Answer : That's what echo does: echo "Some text here." > myfile.txt Sounds like you're looking for a Here document cat > outfile.txt <<EOF >some text >to save >EOF Here's another way - cat > outfile.txt >Enter text >to save press ctrl-d

Can I Rename Files In A Directory With Vim?

Answer : Yes, it can't be done like that. That "file-browser-type interface" is provided by a built-in plugin called netrw. It is read-only so yeah, you can't modify it. You are supposed to hit R to rename the file under the cursor or the marked files. See :help netrw , :help netrw-browse-maps and more specifically :help netrw-R . If you want to batch-rename files using Vim you should try qmv from the renameutils package or vidir from the moreutils package (thanks to Dmitry for the heads up). Check out the renamer.vim - Use the power of vim to rename groups of files plugin (now purely maintained on GitHub). Like netrw , it presents the directory contents in a scratch buffer, and then lets you edit that buffer, and finally apply the edits to the underlying files.

Change Working Directory In Shell With A Python Script

Answer : Others have pointed out that you can't change the working directory of a parent from a child. But there is a way you can achieve your goal -- if you cd from a shell function, it can change the working dir. Add this to your ~/.bashrc: go() { cd "$(python /path/to/cd.py "$1")" } Your script should print the path to the directory that you want to change to. For example, this could be your cd.py: #!/usr/bin/python import sys, os.path if sys.argv[1] == 'tdi': print(os.path.expanduser('~/long/tedious/path/to/tdi')) elif sys.argv[1] == 'xyz': print(os.path.expanduser('~/long/tedious/path/to/xyz')) Then you can do: tdi@bayes:/home/$> go tdi tdi@bayes:/home/tdi$> go tdi That is not going to be possible. Your script runs in a sub-shell spawned by the parent shell where the command was issued. Any cd ing done in the sub-shell does not affect the parent shell.

Capturing STDERR And STDOUT To File Using Tee

Answer : The latter; it makes sure STDOUT and STDERR of the original command go to the same fd, then feeds them jointly into tee. In the former case, it's the STDERR of the tee command that you'd be joining with its STDOUT.
Answer : Resolving the operation not permitted error: sudo chmod u+x my_script.sh You created the file via: sudo vi my_script.sh # editing This means, the owner and group of the file is root. You are not allowed to change files of it by default. You need to change permission (chmod does it) or change the owner: sudo chown you:yourgroup my_script.sh This should do it. Save the trouble, without creating the file via sudo. You've created file my_script.sh with the root user as the owner (because you used sudo ), which is why you're not permitted to change the permissions as yourself . Thus, use sudo chmod u+x my_script.sh , but note that that will make the file only executable for the root user. To make the file executable by everyone, use sudo chmod a+x my_script.sh .