This article is probably not only for absolute beginners, so many Linux guys do not know they can just execute a GUI program on their remote machine but the output of the graphics to be drawn in the local display, it’s like your local display is connected to the remote computer through the network. And you do not need any special software like VNC Client/Server, TeamViewer – all you need is the OpenSSH package you probably have when managing a remote machine. And it is absolutely secure because all the communication is performed within ssh.
Suppose you have a machine, which has some GUI capabilities (you know if we speak for servers, not all servers need the GUI, but in some cases we need it) and you want to execute a graphical program on the remote.
Here is how you can login to be sure you can execute the program remotely:
This command will execute virtualbox on your remote machine with login myuser@192.168.0.245 and the output the display on your local machine.
Here are some examples. Gentoo Desktop using KDE with konsole get to the remote machine on our local network 198.160.245:
SCREENSHOT 1) Login in your remote machine and there type firefox. The firefox will be executed on the remote machine, but the graphics will be output on your local display.
Here is the fast command to see which Linux kernels are available to install from the Ubuntu package management system:
apt update
apt list linux-*image-*
Always update to download the latest metadata files for the available packages and the list with a pattern. In our case we want the Ubuntu kernels and they start with “linux-“, before it was easy linux-image-*, but now there are two types of kernels:
Signed Linux kernel with name starting “linux-signed-image-” (and alias is “linux-image-“) – “Signed with the Ubuntu EFI key”, which means you should have UEFI BIOS and unsigned (with two words – “more security”)
Good old kernel format (so no signing) with name starting “linux-image-unsigned-” – to be sure you pull the unsigned version
And you can use:
apt search linux-*image-*
to see the kernels available and their descriptions. Keep on reading!
This small article is for you who wonder why a configure script under Linux failed with an error like:
configure.ac:204: error: possibly undefined macro: AC_MSG_ERROR
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
configure.ac:216: error: possibly undefined macro: AC_CHECK_LIB
configure.ac:328: error: possibly undefined macro: AC_CHECK_HEADER
autoreconf: /usr/bin/autoconf failed with exit status: 1
FAILED
So autoreconf failed with missing macros, but you just saw you had the latest version and no clue what is wrong with the code you tried to compile!
In most cases the problem is trivial – you are missing the
pkg-config
It is a helper tool used when compiling. It helps to have the correct compiler options and not to hard-coded them in your files. So search for this tool in your Linux distro and install it.
If you have a hung process and it happened to be in this state because of the network, for example your client or server program is in read timeout state, you can use
lsof and gbg
to close the network socket simulating the other (remote) end closed it and the process will continue operating normally.
In our case there is a couple of nrpe process hung in read from a network socket:
As you can see the FD column shows the File Descriptor number of the opened file (network resource here) and you can use it with
gdb
to simulate closing the network socket as if the remote close it but from the same machine.
[root@srv ~]# gdb -p 9948
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-110.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Attaching to process 9948
Reading symbols from /usr/sbin/nrpe...Reading symbols from /usr/sbin/nrpe...(no debugging symbols found)...done.
(no debugging symbols found)...done.
....
....
Loaded symbols for /lib64/libpcre.so.1
Reading symbols from /lib64/libnss_files.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/libnss_files.so.2
0x00007f91e8295c70 in __read_nocancel () from /lib64/libc.so.6
Missing separate debuginfos, use: debuginfo-install nrpe-3.2.0-6.el7.x86_64
(gdb) call shutdown(6, 0)
$1 = 0
(gdb) quit
A debugging session is active.
Inferior 1 [process 9948] will be detached.
Quit anyway? (y or n) Y
Detaching from program: /usr/sbin/nrpe, process 9948
Just call
call shutdown(FileDescriptorID, 0)
and quit the gdb. In our case the FileDescriptorID is 6, so we executed
call shutdown(6, 0)
And the network socket between this machine and the remote one will be terminated, so the process nrpe could continue its execution.
Of course, in your cases you can look for a specific network connection among many other, but lsof is the tool you can use to identify the connection and the right file descriptor number to use in gdb.
If you have a big storage for let’s say your cache proxy and you may want to delete some files fast you could use
find
linux command to delete files. There are plenty examples in the Internet how to do it but many of them use pipes and sorts or other manipulation of the output, which could require the whole output before running some of the piped commands and if you have millions of files you could wait for an hour or two before the command to run and then to see it is not efficient for you case!
So we need a command (or commands), which begins to delete files immediately with some sort of simple selection. We can use linux command “find” with the most used options like
“-type f” – only files
“-mtime +/-N” – only files older or newer than N days. “-mtime +5” – files or directory older than 5 days and “-mtime -5” files or directory newer than 5 days
“-name ‘*.jpg'” – files or directories with patterns in the name *.jpg, for example “sample.jpg”
So we’ll use
“find” to delete files
and a while cycle periodically to check for the free space
and if the free space gets greater than we would like we will kill the find command.
This approach is probably the most effective one, because we run only once the “find” command – if you have multiple runs of the find command in directory with many sub-directories it will check them on every execution in the same order – you may imagine what is like to have hundreds of thousands sub-directories full of files!
The goal is to execute only one find command and to stop it when we reach the desired free space!
So here an example:
echo "STARTING WITH /mnt/cache/"
find /mnt/cache/ -type f -name '*.jpg' -mtime +60 -delete &>/dev/null &
PID=$!
stime=60
while kill -0 "$PID" >/dev/null 2>&1; do
FREESPACE=$(($(stat -f --format="%a*%S/1024" "/mnt/cache/")))
if [[ $FREESPACE -gt 50000000 ]]
then
kill "$PID"
break
fi
echo "SLEEPING FOR $stime"
sleep ${stime}s
done
echo "TERMINATING"
exit 0
The above piece of bash code will find in /mnt/cache/ only files with names ‘*.jpg’ and older than 60 days and will delete them. In parallel we check if the find command is still executing (because it could return finding nothing or just a small amount of files) and sleep for a 60 seconds. If there is 50000000 kylobites (50Gbytes) it will kill the find command!
Someone would argue we could have used
timeout command,
but this will kill “find” every time the check time passes and on every execution of find there will be the same files to check from the previous run!!! And if the first “find” command passed 10000 files and deleted 100, the second time it will check again this 9900 not deleted files and then will continue with the new one and if you execute it again and again you could enter in a endless loop, because the time is used only for checking the files previously checked and not deleted.
Here is the bash script with two parameters for the command line:
#!/bin/bash
if [ "$1" == "" ]
then
echo "USAGE: <script> <path> <time=60s>"
exit 0
fi
if [ "$2" == "" ] || [ "$2" == 0 ]
then
stime=60
else
stime=$2
fi
sleep ${stime}s
echo "STARTING WITH $1"
find "$1" -type f -delete &>/dev/null &
PID=$!
while kill -0 "$PID" >/dev/null 2>&1; do
FREESPACE=$(($(stat -f --format="%a*%S/1024" "$1")))
if [[ $FREESPACE -gt 50000000 ]]
then
kill "$PID"
break
fi
echo "SLEEPING FOR $2"
sleep ${stime}s
done
echo "TERMINATING"
exit 0
Check for the missing two parameters. The second parameter is not mandatory and the default value is 60s. Probably you can tune the script for your needs:
the find commands to look for specific files with name/mtime/type and so on.
third parameter in the command line to set minimum free space to check.
the time of the second parameter to be passed with the argument for s=seconds, m=minutes, h=hours and so on.
Here is a quick Linux tip for those who want to replace their old IP with new one for all files in a given directory and all its sub-directories recursively:
find [path-to-directory] -type f -print0 | xargs -0 sed -i 's[old-IP-escape-dot]/[new-IP]/g'
Quick example:
find /etc/nginx/ -type f -print0 | xargs -0 sed -i 's/192\.168\.10\.124/10.10.10.224/g'
As you can see the directory is “/etc/nginx” and replace it with the directory where are your (configuration) files are. We are replacing old IP=192.168.10.124 with the new one 10.10.10.224, so after the execution of the above line you’ll get modified files with IP 10.10.10.224. You must escape the dot “.” in the IP!
Here are the steps needed to make a secure transfer of your funds under linux distro of Ubuntu. To be able to transfer money safely without any 3rd party involved (no online wallet) just funds from your personal Ethereum wallet address on your computer to another Ethereum wallet address we need the official command line interface for running a full ethereum node:
geth
STEP 1) Install and run an Ethereum node with geth
You can see there are 0.105 Ethers in the Ethereum wallet address 30d8810bb1a74e808b46788b2316bd93cf056517, replace the address with your public address.
STEP 3) Unlock your account
As you remember your wallet private key is encrypted with a password, so before you can use the private key to send funds you must decrypt the key with:
So your key will stay dectrypted for 300 seconds, this is the purpose of the third parameter. It can be omitted.
STEP 4) Send the amount you like to the Ethereum wallet address you like
, BE CAREFUL the operation is irreversible, if you put wrong address or unknown or unexciting one, you’ll lose your Ether coins!!
Every transaction has a cost, which is computed by the miners. That’s why the gas price is dynamic. The price is determined by the miner of a block and it can change from block to block. You can check the gas price here on http://ethgasstation.info. Determining and computing the price in Ether is very difficult there could be at least 3 new howtos about that. The best and the easiest way is just to check a site (like http://ethgasstation.info) for the average gas price in dollars and when executing a transaction of sending Ethereum funds make sure the same amount of Ether in dollars will stay in your wallet address to be used for the gas.
> eth.sendTransaction({from: '30d8810bb1a74e808b46788b2316bd93cf056517', to: '9009a960fb38c379813a4a2e26c5b94909dc8599', value: web3.toWei(0.104, "ether")})
"0x31b4f213f88f2831756bd9cc37b12e80c6dfe413a3b3423659ca91be352961fc"
If you see the transaction ID, it means the you have executed the command successfully and you can check the status of the transaction.
STEP 5) Check the transaction status.
The status of your transaction could be checked in sites offering Ethereum block explorer sites like
, which shows the network time synchronization status of your server under Ubuntu 16, but the older version or other linux distros do not have this program. The output of the program is:
srv@local # ntpstat
synchronised to NTP server (129.250.35.250) at stratum 3
time correct to within 133 ms
polling server every 1024 s
As you can see the time is correct within some interval of milliseconds. In other words your time in the server could be trusted only within these milliseconds! If your server is synchronized with the program ntp your time of the server will be correct within a tiny fractions of a second, closer to a time server much smaller interval of correctness. The interval is computed according to how away the server is and how much the latency of the network of the server is.
ntpstats compute the output with the formula:
rootdisp + rootdelay / 2.0
rootdisp – indicating the maximum error relative to the primary reference source. If your server gets the time from an external source (GPS, radio, high precise clock external device), this value is the estimated maximum error of that clock and if your server gets the time from another NTP server (in most cases), this value is the current NTP server’s root dispersion (to which your server is synced) plus the dispersion added by the network link between your server and the NTP server
rootdelay – indicating the total roundtrip delay to the primary reference source. Because it is a roundtrip we divide it to 2 to get the single trip delay of the network
You can get these two values with the ntpq program:
There a situations when we need to delete a great deal of files from our filesystem and if we just execute
rm -Rf
the server will surely get loaded and the service it provides will degrade! What if you cannot reformat the filesystem, because the server use it extensively, but you need to delete let’s say a couple of millions file from it? We can use find and usleep (in most linux distro this program is installed by an additional package). The idea is to delete files one by one tuning the pause between every delete. Here you can execute this command in the background or a screen:
usleep accepts microseconds, so 200000 microseconds are 0.2 seconds. You can tune it precisely with a step of just a microsecond. In the real world under the bash console we probably will use values of max 1/10 of a second around above 100000 microseconds. Execute the command and then watch your server load and tune.
usleep in CentOS 7 is installed with package “initscripts”, which is installed by default
usleep in Ubuntu is missing and probably won’t find any safe place to download a package to install, but it can be sort of replace with “sleep <floating_point_number>s”, GNU sleep could accept floating point number for the delay and when added “s” at the end it could sleep for a fractions of a seconds. So the command for the Ubuntu is slightly changed:
not GNU version of sleep require NUMBER, so the smallest sleep is only 1 second, which is too big for the purpose. Check your man manual to see if your system has GNU sleep command.
Writing the last howto there was an idea: how to simulate the ESC key, when the key is not available in our keyboard, which is very often these days. Mobile traffic is the ruler coming from mobile devices, of course! So why to limit console users (probably mainly admins?) only to desktop or “qwerty” keyboards? The tables could weight under 500 grams and event smartphones could be used to ssh to a server and what if you do not have ESC key, but need to use it? You can try the following combination:
The escape key can be replaced with pressing and holding CTRL and pressing “[” (left square bracket) = “CTRL+[”
So next time when trying to use ssh or console under Android or iOS or any device try this combination at lease it could be faster than selecting a menu for a predefined keys like ESC key.
Manage Cookie Consent
We use technologies like cookies to store and/or access device information. We do this to improve browsing experience and to show (non-) personalized ads. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.