Page not found – ShopingServer Wiki https://wiki.shopingserver.com Tutorials and Articles About Technology and Gadgets Wed, 02 Sep 2020 02:23:54 +0000 en-US hourly 1 https://wordpress.org/?v=5.5.14 https://wiki.shopingserver.com/wp-content/uploads/2018/07/cropped-favicon-150x150.png Page not found – ShopingServer Wiki https://wiki.shopingserver.com 32 32 W: TMPDIR is Mounted noexec, Will Not Cache Run Scripts Error and Solution https://wiki.shopingserver.com/w-tmpdir-mounted-noexec-will-not-cache-run-scripts-error-solution/ https://wiki.shopingserver.com/w-tmpdir-mounted-noexec-will-not-cache-run-scripts-error-solution/#respond Sat, 06 Jan 2018 10:01:17 +0000 http://wiki.shopingserver.com/?p=18571 I mount /tmp with nodev, nosuid, and noexec options to increase the security of my Linux based web server. And, whenever I ran apt-get install or apt-get upgrade command, I am getting the following error:

apt-get install linux-generic linux-headers-generic linux-image-generic

…..

….

..

Generating grub.cfg …

Found linux image: /boot/vmlinuz-3.2.0-43-generic

Found initrd image: /boot/initrd.img-3.2.0-43-generic

….

ldconfig deferred processing now taking place

Processing triggers for initramfs-tools …

update-initramfs: Generating /boot/initrd.img-3.2.0-43-generic

W: TMPDIR is mounted noexec, will not cache run scripts.

….

How do I fix this problem without compromising security of the data or web-server?

 

You can make /tmp non-executable by setting the following two flags in /etc/fstab file:

noexec – Do not allow direct execution of any binaries or scripts on the mounted filesystem at /tmp.

nosuid – Do not allow SUID or SGID bits to take effect.

nodev – Do not interpret character or block special devices on the file system.

This will safeguard your server against various attacks. But, apt-get upgrade command may fail with the following message:

W: TMPDIR is mounted noexec, will not cache run scripts.

 

apt-get command use /tmp to place scripts and scripts can not execute due to noexec flag on /tmp. To fix your problem edit or create the file /etc/apt/apt.conf (, enter:

# vi /etc/apt/apt.conf

 

OR

$ sudo vi /etc/apt/apt.conf

 

Sample outputs:

DPkg::Pre-Invoke{ mount -o remount,exec /tmp ;};

DPkg::Post-Invoke { mount -o remount,rw,noexec,nosuid,nodev /tmp ;};

Save and close the file. The apt.conf is the main configuration file for the APT suite of tools. The commands are invoked in order using /bin/sh, should any fail APT will abort. Where,

DPkg::Pre-Invoke{ mount -o remount,exec /tmp ;}; – This is a list of shell commands to run before dpkg command. In this example, remove noexec flag from /tmp, so that script can get executed.

DPkg::Post-Invoke { mount -o remount,rw,noexec,nosuid,nodev /tmp ;}; – This is a list of shell commands to run after dpkg. In this example, set noexec and other security flag on /tmp

How do I reinstall and rexecute packages again?

Once you applied the solution as describe above, you can just reinstall the package as follows to run the scripts:

$ sudo apt-get –reinstall install linux-generic linux-headers-generic linux-image-generic

 

In this example,

First, mount -o remount,exec /tmp command will run by apt-get as defined in apt.conf to relax permission on /tmp.

Next, your actual apt-get/dpkg command will get executed to reinstall kernel packages.

Finally mount -o remount,rw,noexec,nosuid,nodev /tmp command will run by apt-get to secure your /tmp.

See also

Man pages – apt.conf(5),apt-get(8),dpkg(1)

 

 

]]>
https://wiki.shopingserver.com/w-tmpdir-mounted-noexec-will-not-cache-run-scripts-error-solution/feed/ 0
CentOS: rpmdb: PANIC: fatal region error detected; run recovery error and solution https://wiki.shopingserver.com/centos-rpmdb-panic-fatal-region-error-detected-run-recovery-error-solution/ https://wiki.shopingserver.com/centos-rpmdb-panic-fatal-region-error-detected-run-recovery-error-solution/#respond Sat, 06 Jan 2018 08:22:12 +0000 http://wiki.shopingserver.com/?p=18453 I

am using a CentOS Linux v6.5 on my home server and I am getting the following error when I execute yum command:

rpmdb: PANIC: fatal region error detected; run recovery

error: db3 error(-30974) from dbenv->open: DB_RUNRECOVERY: Fatal error, run database recovery

error: cannot open Packages index using db3 – (-30974)

error: cannot open Packages database in /var/lib/rpm

CRITICAL:yum.main:

Error: rpmdb open failed

How do I fix this problem on a CentOS / RHEL based system?

 

This is quite the messy situation. You may fix this by cleaning out rpm database. To minimize risk, make a backup of files in /var/lib/rpm/ using cp command:

mkdir /root/backups.rpm.mm_dd_yyyy/

cp -avr /var/lib/rpm/ /root/backups.rpm.mm_dd_yyyy/

To find list of __db* file, enter:

# ls -l /var/lib/rpm/_*

 

Sample outputs:

-rw-r–r– 1 root root   24576 Jan 28 04:00 /var/lib/rpm/__db.001

-rw-r–r– 1 root root  229376 Jan 28 04:00 /var/lib/rpm/__db.002

-rw-r–r– 1 root root 1318912 Jan 28 04:00 /var/lib/rpm/__db.003

-rw-r–r– 1 root root  753664 Jan 28 04:00 /var/lib/rpm/__db.004

To fix this problem, try:

# rm -f /var/lib/rpm/__db*

# db_verify /var/lib/rpm/Packages

# rpm –rebuilddb

# yum clean all

 

Verify that error has gone with the following yum command

# yum update

 

Sample outputs:

 

 

]]>
https://wiki.shopingserver.com/centos-rpmdb-panic-fatal-region-error-detected-run-recovery-error-solution/feed/ 0
X11 forwarding request failed on channel 0 Error and Solution https://wiki.shopingserver.com/x11-forwarding-request-failed-channel-0-error-solution/ https://wiki.shopingserver.com/x11-forwarding-request-failed-channel-0-error-solution/#respond Sat, 06 Jan 2018 08:07:40 +0000 http://wiki.shopingserver.com/?p=18437 I

am a new Linux server user. I need to tunnel X over ssh. I type the following command from OS X Unix terminal to login into far_away_machine (a centos server):

ssh -X -o options -A -p 22 user@centos-far-away-server

But, I am getting the following error on screen:

X11 forwarding request failed on channel 0

Last login: Sun Mar 23 15:58:51 2014 from 1.2.3.4

How do I fix “X11 forwarding request failed on channel 0” on Linux or Unix-like systems?

 

You may get an error when you try to display a server managment app or any other X app. You will be able to run a graphical application on server and get applications display (window) on your desktop using X11 forwarding. The fix this issue make sure OpenSSH SSHD is configured as follows

Fixing forwarding request failed on channel 0 on a Linux/Unix based server

Login to your centos-far-away-server, enter:

$ ssh -A -p 22 user@centos-far-away-server

 

Edit /etc/ssh/sshd_config file, enter:

$ sudo vi /etc/ssh/sshd_config

 

Set the following two options:

X11Forwarding yes

X11UseLocalhost no

Save and close the file. Reload the sshd, enter:

$ sudo /etc/init.d/sshd reload

 

Sample outputs:

Reloading sshd:                                            [  OK  ]

Install X authority file utility

You need to install xauth tool using yum command:

$ sudo yum install xauth

 

Sample outputs:

Loaded plugins: downloadonly, fastestmirror, security

Loading mirror speeds from cached hostfile

* base: mirrors.tummy.com

* epel: mirror.steadfast.net

* extras: centos-mirror.jchost.net

* updates: centos.hostingxtreme.com

Setting up Install Process

Resolving Dependencies

–> Running transaction check

—> Package xorg-x11-xauth.x86_64 1:1.0.2-7.1.el6 will be installed

–> Processing Dependency: libXmuu.so.1()(64bit) for package: 1:xorg-x11-xauth-1.0.2-7.1.el6.x86_64

–> Running transaction check

—> Package libXmu.x86_64 0:1.1.1-2.el6 will be installed

–> Processing Dependency: libXt.so.6()(64bit) for package: libXmu-1.1.1-2.el6.x86_64

–> Running transaction check

—> Package libXt.x86_64 0:1.1.3-1.el6 will be installed

–> Finished Dependency Resolution

 

Dependencies Resolved

 

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

Package                      Arch                 Version                        Repository          Size

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

Installing:

xorg-x11-xauth               x86_64               1:1.0.2-7.1.el6                base                35 k

Installing for dependencies:

libXmu                       x86_64               1.1.1-2.el6                    base                66 k

libXt                        x86_64               1.1.3-1.el6                    base               184 k

 

Transaction Summary

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

Install       3 Package(s)

 

Total download size: 285 k

Installed size: 681 k

Is this ok [y/N]: y

Downloading Packages:

(1/3): libXmu-1.1.1-2.el6.x86_64.rpm                                                |  66 kB     00:00

(2/3): libXt-1.1.3-1.el6.x86_64.rpm                                                 | 184 kB     00:00

(3/3): xorg-x11-xauth-1.0.2-7.1.el6.x86_64.rpm                                      |  35 kB     00:00


Total                                                                      1.2 MB/s | 285 kB     00:00

Running rpm_check_debug

Running Transaction Test

Transaction Test Succeeded

Running Transaction

Installing : libXt-1.1.3-1.el6.x86_64                                                                1/3

Installing : libXmu-1.1.1-2.el6.x86_64                                                               2/3

Installing : 1:xorg-x11-xauth-1.0.2-7.1.el6.x86_64                                                   3/3

Verifying  : libXmu-1.1.1-2.el6.x86_64                                                               1/3

Verifying  : libXt-1.1.3-1.el6.x86_64                                                                2/3

Verifying  : 1:xorg-x11-xauth-1.0.2-7.1.el6.x86_64                                                   3/3

 

Installed:

xorg-x11-xauth.x86_64 1:1.0.2-7.1.el6

 

Dependency Installed:

libXmu.x86_64 0:1.1.1-2.el6                          libXt.x86_64 0:1.1.3-1.el6

 

Complete!

Try ssh command as follows:

$ ssh -X -o options -A -p 22 user@centos-far-away-server

 

Sample outputs:

Last login: Sun Mar 23 16:25:09 2014 from 1.2.3.4

/usr/bin/xauth:  creating new authority file /home/vivek/.Xauthority

Once you got ~/.Xauthority file, you can run X apps as follows over ssh:

$ xeyes &

$ my-cool-raid-app-manager &

Tip: Finding issues with X over ssh

If you still need hints, run ssh command as follows to debug problems:

$ ssh -v user@server-name-here

 

 

]]>
https://wiki.shopingserver.com/x11-forwarding-request-failed-channel-0-error-solution/feed/ 0
Fix: /bin/dbus-launch terminated abnormally without any error message and solution https://wiki.shopingserver.com/fix-bin-dbus-launch-terminated-abnormally-without-error-message-solution/ https://wiki.shopingserver.com/fix-bin-dbus-launch-terminated-abnormally-without-error-message-solution/#respond Sat, 06 Jan 2018 08:05:50 +0000 http://wiki.shopingserver.com/?p=18435 I

am a new Linux server user. I need to tunnel X over ssh. I type the following command on a CentOS/RHEL based remote host to get display on a local desktop:

ssh -X user@server1.cyberciti.biz

xeyes &

firefox &

But, I am getting an error that read as follows:

**error**: Failed to contact configuration server; some possible causes are that you need to enable TCP/IP networking for ORBit, or you have stale NFS locks due to a system crash. See http://projects.gnome.org/gconf/ for information. (Details – 1: Failed to get connection to session: /bin/dbus-launch terminated abnormally without any error message)

How do I fix this error on a newly formatted/installed RHEL or CentOS Linux 6.x server?

 

You need to install D-Bus. It is nothing but a message bus system, a simple way for applications to talk to one another. In addition to interprocess communication, D-Bus helps coordinate process lifecycle; it makes it simple and reliable to code a “single instance” application or daemon, and to launch applications and daemons on demand when their services are needed. You also need to install Fonts on a CentOS/RHEL based system.

To fix /bin/dbus-launch terminated abnormally without any error message on a CentOS/RHEL

Type the following yum command to install D-Bus and Fonts:

$ sudo yum install dbus-x11

 

Sample outputs:

Loaded plugins: downloadonly, fastestmirror, security

Loading mirror speeds from cached hostfile

* base: mirrors.tummy.com

* epel: mirror.steadfast.net

* extras: centos-mirror.jchost.net

* updates: centos.hostingxtreme.com

Setting up Install Process

Resolving Dependencies

–> Running transaction check

—> Package dbus-x11.x86_64 1:1.2.24-7.el6_3 will be installed

–> Finished Dependency Resolution

 

Dependencies Resolved

 

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

Package                 Arch                  Version                           Repository           Size

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

Installing:

dbus-x11                x86_64                1:1.2.24-7.el6_3                  base                 40 k

 

Transaction Summary

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

Install       1 Package(s)

 

Total download size: 40 k

Installed size: 28 k

Is this ok [y/N]: y

Downloading Packages:

dbus-x11-1.2.24-7.el6_3.x86_64.rpm                                                  |  40 kB     00:00

Running rpm_check_debug

Running Transaction Test

Transaction Test Succeeded

Running Transaction

Installing : 1:dbus-x11-1.2.24-7.el6_3.x86_64                                                        1/1

Verifying  : 1:dbus-x11-1.2.24-7.el6_3.x86_64                                                        1/1

 

Installed:

dbus-x11.x86_64 1:1.2.24-7.el6_3

 

Complete!

To install Fonts, type:

$ sudo yum groupinstall  Fonts

Now, you can run and tunnel X over ssh:

$ ssh -X user@server1.cyberciti.biz

$ xeyes

$ firefox

 

 

]]>
https://wiki.shopingserver.com/fix-bin-dbus-launch-terminated-abnormally-without-error-message-solution/feed/ 0
Linux / Unix – crontab: no crontab for user using an empty one error and solution https://wiki.shopingserver.com/linux-unix-crontab-no-crontab-user-using-empty-one-error-solution/ https://wiki.shopingserver.com/linux-unix-crontab-no-crontab-user-using-empty-one-error-solution/#respond Sat, 06 Jan 2018 07:54:34 +0000 http://wiki.shopingserver.com/?p=18419 I

am trying to set cronjob on a Unix systems by running the crontab -e command. But, I’m getting the following error:

crontab: no crontab for veryv – using an empty one

crontab: “/usr/bin/vi” exited with status 1

How do I fix this issue on a Linux or Unix-like systems?

You need to set correct environment variable called EDITOR. It appers that either vi is not installed or /usr/bin/vi is a symbolic link to vim editor. To edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables, enter:

$ crontab -e

But, if EDITOR or VISUAL is not set, so you will see an error as follows:

Fig.01: Linux crontab: no crontab for veryv – using an empty one

So to fix this error and use vim as a text editor, type (bash/sh/ksh shell specific syntax):

export EDITOR=vim

 

OR if you are using emacs editor, run:

export EDITOR=emacs

 

Or if you are using nano text editor, enter:

export EDITOR=nano

 

Finally, try to edit or set new cron jobs, enter:

crontab -e

 

I recommend that you edit your shell ~/.bashrc file and append the following line:

export EDITOR=vim

 

 

]]>
https://wiki.shopingserver.com/linux-unix-crontab-no-crontab-user-using-empty-one-error-solution/feed/ 0
FreeBSD: (EE) Failed to load module “fbdev” (module does not exist, 0) Error and Solution https://wiki.shopingserver.com/freebsd-ee-failed-load-module-fbdev-module-not-exist-0-error-solution/ https://wiki.shopingserver.com/freebsd-ee-failed-load-module-fbdev-module-not-exist-0-error-solution/#respond Fri, 05 Jan 2018 16:31:00 +0000 http://wiki.shopingserver.com/?p=18401 I

‘m installing FreeBSD 10 Xorg and xfce4 desktop. But, getting the following error:

(EE) Failed to load module “fbdev” (module does not exist, 0)

How do I fix this problem on FreeBSD 10 amd64 based system?

 

You need to install the X.Org xf86-video-fbdev driver. This can be installed using either ports or binary package using the pkg command.

Fixing (EE) Failed to load module “fbdev” (module does not exist, 0) on a FreeBSD Xorg

Open the Terminal app and login as root user using su – command:

su –

Install the xf86-video-fbdev via the port

Type the following command:

# cd /usr/ports/x11-drivers/xf86-video-fbdev/

# make install clean

Install the xf86-video-fbdev via the binary package

Type the following command:

# pkg install x11-drivers/xf86-video-fbdev

 

OR

# pkg install xf86-video-fbdev

 

Sample outputs:

Updating repository catalogue

The following 1 packages will be installed:

 

Installing xf86-video-fbdev: 0.4.4_4

 

The installation will require 28 KB more space

 

11 KB to be downloaded

 

Proceed with installing packages [y/N]: y

xf86-video-fbdev-0.4.4_4.txz        100%   11KB  11.1KB/s  11.1KB/s   00:00

Checking integrity… done

[1/1] Installing xf86-video-fbdev-0.4.4_4… done

Test new Xorg config

First, create an Xorg config file:

# Xorg -configure

 

This will generate a file named /root/xorg.conf.new which attempts to load the proper drivers for the detected hardware. Next, test that the automatically generated configuration file works with the graphics hardware by typing:

# Xorg -config xorg.conf.new -retro

 

If the test is successful, copy the configuration file to /etc/X11/xorg.conf:

# cp xorg.conf.new /etc/X11/xorg.conf

References

FreeBSD handbook: Chapter 6. The X Window System

 

 

]]>
https://wiki.shopingserver.com/freebsd-ee-failed-load-module-fbdev-module-not-exist-0-error-solution/feed/ 0
Apple OS X: Install X Window System XQuartz For SSH X11 Forwarding On a Mavericks or Yosemite https://wiki.shopingserver.com/apple-os-x-install-x-window-system-xquartz-ssh-x11-forwarding-mavericks-yosemite/ https://wiki.shopingserver.com/apple-os-x-install-x-window-system-xquartz-ssh-x11-forwarding-mavericks-yosemite/#respond Fri, 05 Jan 2018 15:49:06 +0000 http://wiki.shopingserver.com/?p=18351 I

need to tunnel X Window securely over SSH bases session so that I run X program on my remote Linux/Unix server/workstation and get back display to my Apple Macbook pro laptop. I tried the ssh -X user@server1 and ssh -Y user@server2 commands on both OS X Mountain Lion and Apple OS X Mavericks/Yosemite. But, I am unable to use the ssh command with X11.

How do I fix this problem on OS X and enable X11 forwarding with ssh command? How do I install XQuartz (X11.app) server on Apple OS X Mountain Lion or Mavericks or Yosemite?

 

You need to install XQuartz (X11.app) on OS X v10.8 or above to use ssh with x11 forwarding. The XQuartzproject is an open-source effort to develop a version of the X.Org X Window System that runs on OS X. This is Apple’s version of the X server.

The latest version of Apple OS X Mountain Lion and Mavericks no longer ships with X11.app i.e. XQuartz server. You need to download and install the server before using ssh with X11 forwarding.

Can’t load X11 after OS X Yosemite upgrade

You need to delete / remove existing XQuartz server and reinstall it again.

Step #1: Download and Install XQuartz server

Visit this page and download XQuarz server. Once downloaded the XQuarz package, install the server by double clicking the package icon in your Downloads folder. Please follow the instructions on-screen to complete the installations:

XQuartz Install Step # 1

XQuartz Install Step # 2

XQuartz Install Step # 3

XQuartz Install Step # 4

XQuartz Install Step # 5

XQuartz Install Step # 6

Step #2: ssh X11 forwarding syntax

A tunneling protocol is a network protocol which encapsulates a payload protocol, acting as a payload protocol. Reasons to tunnel include carrying a payload over an incompatible delivery network, or to provide a secure path through an untrusted network. SSH is frequently used to tunnel insecure traffic over the Internet in a secure way. Simply type the following command to use X over ssh:

ssh -X user@RemoteserverNameHere

x-app-name-here &

OR

ssh -X userName@Server-Ip-Address-Here

x-window-app-name-here &

Examples

In this example, login to the Linux based nas01 server as a user called nixcraft:

$ ssh -X nixcraft@nas01

 

OR

$ ssh -X nas01

 

You will see XQuartz server in the Dock i.e. a new XQuartz icon sits at the bottom of side of your screen as follows:

Fig.01: X11.app ( XQuartz ) loaded at the Dock

 

To test X11 by running xeyes or xclock or any another GUI application you wish. The syntax is as follows on your remote server:

$ app-name

$ /path/to/app-name

$ app-name &

 

In this example, I am running xeyes on remote server:

$ xeyes

 

Sample outputs:

Animated gif 01: X11 Forwarding on OS X v10.8+. This demo was tested on OS X 10.9 i.e. Mavericks and Linux remote server.

Edit your ~/.ssh/config file and append the following line and you wouldn’t need pass the -X option to ssh command:

ForwardX11 yes

Finally, you can run ssh in the background after running a GUI app as follows:

ssh user@server -f -X app-Name

ssh nixcraft@nas01 -f -X gpass

ssh nixcraft@nas01 -f -X xeyes

See also

Man pages: ssh_config(5),sshd(8),ssh(1)

 

 

]]>
https://wiki.shopingserver.com/apple-os-x-install-x-window-system-xquartz-ssh-x11-forwarding-mavericks-yosemite/feed/ 0
Use ssh-copy-id with an OpenSSH Server Listening On a Different Port https://wiki.shopingserver.com/use-ssh-copy-id-openssh-server-listening-different-port/ https://wiki.shopingserver.com/use-ssh-copy-id-openssh-server-listening-different-port/#respond Fri, 05 Jan 2018 15:43:28 +0000 http://wiki.shopingserver.com/?p=18343 M

y OpenSSH server listening on TCP port number 2222. How can I use ssh-copy-id with an sshd server with listening on a different port on a Linux or Unix-like systems?

 

The ssh-copy-id is a shell script that uses ssh command to log into a remote machine using a login password to install your public key in a remote machine’s authorized_keys. The script also secure the remote user’s home, ~/.ssh, and ~/.ssh/autho-rized_keys files by changing the permissions.

Syntax

The syntax is as follows to install ssh-keys:

ssh-copy-id user@server-name-here

ssh-copy-id -i /path/to/identity-file user@server-name-here

Examples

Install key for server42, enter:

ssh-copy-id vivek@nas01

Install key for for OpenSSH server listen on IP 192.168.1.146 port 22 (default), enter:

ssh-copy-id nixcraft@192.168.1.146

Sample outputs:

/usr/local/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed

/usr/local/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed — if you are prompted now it is to install the new keys

nixcraft@192.168.1.146 s password:

 

Number of key(s) added:        1

 

Now try logging into the machine, with:    ssh  nixcraft@192.168.1.146

and check to make sure that only the key(s) you wanted were added.

Using ssh-copy-id with an SSH server listening on a different port # 2222

If your remote server listen on a different port than 22, you need to use the following syntax:

old syntax. only valid for older ssh-copy-id (see below for new syntax) ##

ssh-copy-id  -p PORT-NUMBER-HERE user@server-name-here

ssh-copy-id  -p 2222 vivek@server1.cybercit.biz

ssh-copy-id  -p 2222 nixcraft@192.168.1.146

OR

new syntax ##

ssh-copy-id -p 2222 nixcraft@192.168.1.146

Sample outputs:

Fig.01: Using ssh-copy-id with an SSH server listening on a different port # 2222

TEST IT

Now try logging into the machine, with:

ssh -p 2222 nixcraft@192.168.1.146

Sample outputs:

Welcome to Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-46-generic x86_64)

 

* Documentation:  https://help.ubuntu.com/

 

Last login: Sat Mar  7 17:55:48 2015 from viveks-macbook-pro.local

See ssh-copy-id(1) for more info.

 

 

]]>
https://wiki.shopingserver.com/use-ssh-copy-id-openssh-server-listening-different-port/feed/ 0
FreeBSD Unix Find Out Which Programs Are Listening On a Given Port Number https://wiki.shopingserver.com/freebsd-unix-find-programs-listening-given-port-number/ https://wiki.shopingserver.com/freebsd-unix-find-programs-listening-given-port-number/#respond Fri, 05 Jan 2018 15:40:55 +0000 http://wiki.shopingserver.com/?p=18339 I

‘m a new FreeBSD Unix system user. How can I find out the process/programs names listing on a certain port on a FreeBSD Unix systems using command line? How do I lookup the process which is currently bound to the given network port on a FreeBSD server?

 

You can use any one of the following command-line tools that displays network connections, routing tables, and a number of network interface statistics on a FreeBSD operating systems.

netstat command – Use to see network status including open ports, tcp/udp connections, and more.

sockstat command – Show open sockets.

lsof command – List open files such as network sockets and files on disks.

FreeBSD has a command called sockstat and netstat tools. These are already on a standard FreeBSD install. You need to install the lsof tool from ports collection.

Find the process listening on a certain port using the sockstat command

An example of the netstat command with flags:

Show listening sockets ##

sockstat -l

 

Show listening sockets for IPv4 only ##

sockstat -4 -l

 

Show listening sockets for IPv6 only ##

sockstat -6 -l

Sample outputs:

Fig.01: FreeBSD sockstat command in action

 

Where,

USER : The user who owns and open the socket.

COMMAND : The command which is responsible for the socket.

PID : The process ID of the command which responsible/holds the socket.

FD : The file descriptor number of the socket.

PROTO : The transport protocol associated with the socket for Internet sockets, or the type of socket (stream or datagram) for UNIX sockets.

LOCAL ADDRESS : For Internet sockets, this is the address the local end of the socket is bound to. For bound UNIX sockets, it is the socket’s filename. For other UNIX sockets, it is a right arrow followed by the endpoint’s filename, or ‘??’ if the endpoint could not be determined.

FOREIGN ADDRESS : (Internet sockets only) The address the foreign end of the socket is bound to.

Find selected ports

You can use the grep command to select a certain ports. In this example, find out if port 22 and 80 is open or not:

sockstat -4 -l | grep :22

sockstat -4 -l | grep :80

Sample outputs:

root     sshd       642   4  tcp4   *:22                  *:*

Show connected sockets only

The syntax is:

sockstat -c

sockstat -c -4

sockstat -c -4 | grep ssh

sockstat -c -4 | grep 22

root     sshd       740   3  tcp4   192.168.1.142:22      192.168.1.4:55115

(192.168.1.4 == client IP and 192.168.1.142 == server IP for port 22)

netstat command example to find out open ports and their process

Here the equivalent of netstat:

netstat -a -n | grep LISTEN

netstat -a | egrep  LISTEN|Proto|Active

netstat -a | egrep  Proto|LISTEN

Sample outputs:

Active Internet connections (including servers)

Proto Recv-Q Send-Q Local Address          Foreign Address        (state)

tcp4       0      0 localhost.smtp         *.*                    LISTEN

tcp4       0      0 *.ssh                  *.*                    LISTEN

tcp6       0      0 *.ssh                  *.*                    LISTEN

Active UNIX domain sockets

Even though sockstat is thought to be more limited, it is nice to know because at times it can be more useful in gathering certain information. On a FreeBSD, you can get a listing of standard port associations by looking in the /etc/services. If you wanted to find out the purpose of port 631, you can use this command for example:

$ grep -w 631 /etc/services

ipp  631/tcp    #IPP (Internet Printing Protocol)

ipp  631/udp    #IPP (Internet Printing Protocol)

what the purpose of port 22 ?##

$ grep -w 22 /etc/services

ssh   22/sctp   #Secure Shell Login

ssh   22/tcp    #Secure Shell Login

ssh   22/udp    #Secure Shell Login

It’s handy if you don’t know about ports and are learning about it.

Use lsof command to determine the process/pid listening on a certain port

Some people who have migrated from Linux to BSD like lsof command. It isn’t standard like netstat and sockstat. You will have to install it. At this time there is no package.

To install it as root. So first, install the lsof command using the port:

# cd /usr/ports/sysutils/lsof/ && make install clean

 

Or use the pkg command (warning this may not work on the latest release 10.x):

# pkg install sysutils/lsof

 

Sample outputs:

Updating FreeBSD repository catalogue…

FreeBSD repository is up-to-date.

All repositories are up-to-date.

Checking integrity… done (0 conflicting)

The following 1 packages will be affected (of 0 checked):

 

New packages to be INSTALLED:

lsof: 4.89.c,8

 

The process will require 224 KiB more space.

 

Proceed with this action? [y/N]: y

[1/1] Installing lsof-4.89.c,8…

[1/1] Extracting lsof-4.89.c,8: 100%

To discover the process name, ppid, and other details you need to use the following syntax:

lsof -i :port

lsof -i tcp:portNumber

lsof -i udp:portNumber

For example, see which process is listening upon port 80 or 22 you can run:

lsof -i :80

OR

lsof -i :22

Sample outputs:

COMMAND PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME

sshd    642 root    3u  IPv6 0xfffff8000961a400      0t0  TCP *:ssh (LISTEN)

sshd    642 root    4u  IPv4 0xfffff8000961a000      0t0  TCP *:ssh (LISTEN)

sshd    740 root    3u  IPv4 0xfffff800094dec00      0t0  TCP 192.168.1.142:ssh->192.168.1.4:55115 (ESTABLISHED)

To list all open TCP process and their pids, enter:

lsof -iTCP -sTCP:LISTEN

lsof -iTCP -sTCP:LISTEN -P -n

lsof -n -P -i +c 15

Sample outputs:

Fig.02: Find out which process is listening upon a port using lsof utility

References

For information read sockstat command man page:


$ man sockstat

 

For information read netstat command man page:


$ man netstat

 

Not a fan of FreeBSD? See how to find out which process is listening upon a port on a Linux operating systems for more info.

This quick tutorial was contributed by Wendy Michele. Editing by admin. You can too contribute to nixCraft.

 

 

]]>
https://wiki.shopingserver.com/freebsd-unix-find-programs-listening-given-port-number/feed/ 0
How to find out information about a LXC (Linux container) CPU & Memory Usage https://wiki.shopingserver.com/find-information-lxc-linux-container-cpu-memory-usage/ https://wiki.shopingserver.com/find-information-lxc-linux-container-cpu-memory-usage/#respond Fri, 05 Jan 2018 14:39:57 +0000 http://wiki.shopingserver.com/?p=18262 H

ow can I find out information about a Linux container (LXC) such as CPU usage and memory usage from the command prompt? Is there is top command like a tool for lxc to monitor memory and cpu usage?

 

You need to use the lxc-info command to display the following information about a LXC:

CPU usage in seconds.

Block I/O usage.

Memory usage.

Kmem (kernel memory) usage.

Networking TX/RX usage.

lxc-info syntax and example

The syntax is:

lxc-info -n {container-name-here}

lxc-info [options] -n {container-name-here}

To display information for cyberciti container, enter:

# lxc-info -n cyberciti

 

Fig.01: lxc-info in action

Show information for all containers whose name starts with nixcraft, run:

# lxc-info -n  nixcraft.*

Just print the container’s state

# lxc-info -s -n lxcdb

Just print the container’s pid

# lxc-info -p -n lxmemcache

ust print the container’s IP addresses

# lxc-info -i -n lxnginx

Say hello to lxc-top

You can use the lxc-top command to monitor container statistics. The output is updated every 3 seconds and is ordered according to the sortby value given by the user. The syntax is:

lxc-top

lxc-top [options]

Set amount of time in seconds to delay between screen updates:

# lxc-top –delay 5

 

To Sort the containers by name, cpu use, or memory use. The sortby argument should be one of the letters n,c,b,m,k to sort by name, cpu use, block I/O, memory, or kernel memory use respectively. The default is ‘n’.

# lxc-top –sort {sortby}

[ CPU usage ]

# lxc-top –sort c

[ memory usage ]

# lxc-top –sort m

htop cgroup option

First, install htop on a Linux operating system using the yum or apt-get:

$ sudo apt-get install htop

 

OR

$ sudo yum install htop

 

Start the htop, enter:

# htop

 

Press F2 special key to enter into setup mode. Choose SETUP > Columns > Choose CGGROUP from Available Columns > Press F10 to save the changes:

Fig.02: Display htop cgroups columns on a Linux

 

You should see output as follows:

Fig.03: htop in action

 

 

]]>
https://wiki.shopingserver.com/find-information-lxc-linux-container-cpu-memory-usage/feed/ 0