Monday, April 27, 2015

Check postfix email queue, and how to clear emails in there

To check the queue, we use a command called mailq, example as below:

$ mailq | tail

2024F98A61     3505 Mon Apr 27 18:16:17  support.us@something.com
(delivery temporarily suspended: Host or domain name not found. Name service error for name=smtp.something.com type=AAAA: Host not found)
                                         support.us@somethingelse.com
231EC98AED     3525 Fri Apr 24 16:48:04  support.us@something.com
(delivery temporarily suspended: Host or domain name not found. Name service error for name=smtp.something.com type=AAAA: Host not found)
                                         whoami@somethingelse.com

To clear the email in the queue, a command called postsuper is used, as below:

$ sudo postsuper -d ALL

To check the status of deletion, you can refer to the maillog, in below example, 15 messages have been deleted:

$ sudo tail /var/log/maillog

Apr 27 19:44:02 au-mel-rh-dev-3 postfix/smtp[6927]: 46F5598AF7: to=, relay=mta5.am0.yahoodns.net[98.138.112.37]:25, delay=2568, delays=2562/0.02/4.3/2, dsn=2.0.0, status=sent (250 ok dirdel)
Apr 27 19:44:02 au-mel-rh-dev-3 postfix/qmgr[5985]: 46F5598AF7: removed
Apr 27 19:44:04 au-mel-rh-dev-3 postfix/smtp[6925]: ABA8B98AFA: to=, relay=mta5.am0.yahoodns.net[98.138.112.34]:25, delay=1624, delays=1617/0.02/4.4/3.3, dsn=2.0.0, status=sent (250 ok dirdel)
Apr 27 19:44:04 au-mel-rh-dev-3 postfix/qmgr[5985]: ABA8B98AFA: removed
Apr 27 19:49:27 au-mel-rh-dev-3 postfix/postsuper[7913]: Deleted: 15 messages



Monday, April 20, 2015

xrdp is not accessible with "X server -- no display in range is available" error

From rdp client, it is showing below error:












Checking on the log, this is the error:

$ sudo tail -f  /var/log/xrdp-sesman.log
...
[20150420-09:55:01] [INFO ] scp thread on sck 7 started successfully

[20150420-09:55:02] [INFO ] ++ created session (access granted): username mrapp, ip 10.157.4.55:53456 - socket: 7

[20150420-09:55:02] [INFO ] starting Xvnc session...

[20150420-09:55:02] [ERROR] X server -- no display in range is available


Searching on the web, I stumbled upon a site. Below are the steps that I learned to solve the above issue from the site:
  1. Edit /etc/xrdp/sesmain.ini
  2. Change MaxSessions from 10 to 100 
  3. $ sudo diff -u {~,/etc/xrdp}/sesman.ini
    --- /home/mrapp/sesman.ini      2012-10-29 20:58:30.000000000 +0700
    +++ /etc/xrdp/sesman.ini        2015-04-20 09:56:31.277342575 +0700
    @@ -13,7 +13,7 @@
    
    
     [Sessions]
     X11DisplayOffset=10
    -MaxSessions=10
    +MaxSessions=100
     KillDisconnected=0
     IdleTimeLimit=0
     DisconnectedTimeLimit=0
  4. Restart xrdp
    $ sudo /etc/init.d/xrdp restart
Try to connect with your rdp client, it should work now.

Wednesday, March 11, 2015

Connecting to your machine using vnc

To setup and use vncserver in redhat flavored distro, please follow below steps:

  1. Install the package:
    $ sudo yum install tigervnc-server tigervnc
  2. Set a password for a user that you want to use to login to the vnc server:
    $ vncpasswd
  3. Start the vncserver:
    $ vncserver
  4. Check the display number of your newly created vnc session:
    $ vncserver -list
    TigerVNC server sessions:
    X DISPLAY #     PROCESS ID
    :1              9168
  5. Check the port that your vnc session is using:
    $ sudo netstat -tulpn | grep 9168
    tcp        0      0 0.0.0.0:5901                0.0.0.0:*                   LISTEN      9168/Xvnc
    tcp        0      0 0.0.0.0:6001                0.0.0.0:*                   LISTEN      9168/Xvnc
    tcp        0      0 :::6001                     :::*                        LISTEN      9168/Xvnc
  6. Test your vncserver locally (only if you are using GUI, else test it from the other machine with vncviewer installed), using vncviewer (belongs to tigervnc package):
    $ vncviewer :1

To connect from a redhat flavored linux distro client:
  1. Install the tigervnc package:
    $ sudo yum install tigervnc
  2. Run the vncviewer: vncviewer :
    $ vncviewer 192.168.0.2:1
    
  3. If you are behind firewall, you need to open port 5901 for the client to get through.
  4. If firewall is not in your control, you can always use ssh to port forward port 5901 to 5901 in your localhost, by: 
  5. $ ssh -L 5901:localhost:5901 vncserver.ip.address
    and in other terminal, run
    $ vncviewer localhost:1

Once you are done, you can kill the server by running:

$ vncserver -kill :1

Thursday, February 19, 2015

Starting with tmux - putting in initial settings

After a few years using GNU screen as my main terminal multiplexer, I have now changed it to tmux. The reasons behind that are:

  1. A lot more customizable
  2. The commands are also available in easy human understandable language, rather than just the shortcuts. For example: to kill a window, just "ctrl-b" and type "kill-window" or "killw", which is easier for new user like me to remember and use, rather than shortcuts like "ctrl-b &" which sometimes can be confusing.
  3. Easier horizontal and vertical splitting mechanism

To start with tmux, especially if you are coming from screen, it is very important to set th ekey binding right, since ctrl-b is not easily reachable with one hand compared to ctrl-1. Below are my initial .tmux.conf settings, to ease up my transition from GNU screen to tmux.

$ cat .tmux.conf
# unbind control-b, and replace it with control-a (GNU screen style)
set-option -g prefix C-a
           unbind-key C-b
           bind-key C-a send-prefix
# Use vi or emacs-style key bindings in copy and choice modes
set-window-option -g mode-keys vi       
# start windows numbering at 1
set -g base-index 1
# renumber windows when a window is closed                     
set -g renumber-windows on              

So there you go, some very simple settings to be appended to .tmux.conf, to ease up your learning in using tmux. Please refer to the comments, to actually know what the settings are for. You can always refer to tmux manual (man tmux) for more settings.

Hope this will be helpful :)

Thursday, February 12, 2015

Accessing other user's screen session

This need usually arises, when in a multi user machine, you as an admin wanted to check what is other user is running using screen. The best you can see even as root using ps, is just the name of the command, like below:

michael@vbox:~$ sudo ps awxuf | grep -i screen

root      1135  0.0  0.0  13636   976 pts/1    S+   13:27   0:00                          \_ grep --color=auto -i screen

john   4245  0.0  0.0 387364 16668 ?        Sl   Feb02   0:06  |       \_ gnome-screensaver

1001      6762  0.0  0.0 347384 10428 ?        Sl   Feb02   0:00              \_ gnome-screensaver

john    625  0.0  0.0  31320  1568 ?        Ss   11:57   0:00 SCREEN -S test

michael@vbox:~$ pstree -Gap 625

screen,625 -S test

  └─bash,626



When you try to access the screen session using other user, this is usually the error:

michael@vbox:~$ sudo -u john screen -r 625
Cannot open your terminal '/dev/pts/1' - please check.


This is because, your terminal: /dev/pts/1 is only readable and writable to the owner of the terminal:


michael@vbox:~$ ls -lh /dev/pts/1
crw--w---- 1 john tty 136, 1 Feb  12 13:30 /dev/pts/1


To overcome this, simply allow read and write to the terminal, to all users:
john@vbox:~$ chmod o+rw /dev/pts/1
john@vbox:~$ ls -lh /dev/pts/1
crw--w-rw- 1 john tty 136, 1 Feb  12 13:32 /dev/pts/1


Once that done, you can use sudo to access the screen of the other user:
michael@vbox:~$ sudo -u john screen -r 625


Hope this help :).