Saturday, March 2, 2013

Changing permissions (ownership) of directory or file including access permissions in Ubuntu

Sometimes users may need to change the permissions of a directory or a file in order to prevent of unauthorized accesses.If sometimes you need to give access to some user on file or a directory which owns by the root, then you need to give the permission to that particular user.Let's see how this goin to work.

Changing the ownership of filename

To change the ownership of a single file, you can run following command with specifing username and user group. 

         sudo chown <username>:<groupname> <filename>

         example :

                        sudo chown harsha:harsha textfile.txt


To change the ownership of a single file with only specifying username only you can run following command.

          sudo chown <username> <filename>

          example :
                        sudo chown harsha textfile.txt


Changing the ownership of directory
To change the ownership of a directory you can following command which recursively apply the ownership changes to sub directories and files also.

         sudo chown -R <username>:<groupname> < directory >
         example :
                              sudo chown harsha:harsha textDirectory/


By only username

         sudo chown -R <username> < directory >

         example :
                        sudo chown harsha textDirectory/


Access permissions
In the above posts I have describe how to change the ownership of a directory  or file.But for a movement if you change the ownership to root and let only root can access the directory and files you may need to change the access permissions to particular directory.

If you want to get a quick understanding about the permission matrices which  show the read write and execute permissions in Linux I recommand this link will provide better understanding.Numbers coming along with "chmod" command are the way of expressiong permissions.


How To change permission of file folder so only root can access open it

Step 1
  •  Change the ownership of the directory / file to root
       sudo chown root:root <direcotry or filename>
         
         example:
                sudo chown root:root textDirecotry/
Step 2             

  • Change the permissions so that only the owner of the file can read/write/execute it.(There is no point of applying permission for all the directories,cause if particular user cannot access root directory,then user won't be able to access the files and directories inside the root directory)
                 sudo chmod 700 <direcotry or filename>
        
         example:
                              sudo chmod 700 textDirecotry/


If file is a executable file you may give "sudo chmod 700" instead of "sudo chmod 600".

Details about permission numbers

  • chmod 700 
The directory’s owner can read or write files in that directory as well as change to it.
All other users (except root) have no access.
  • chmod 771 
Same as for the owner. All other users can change to the directory, but not view or change files
in the directory. This can be useful for server hardening,where you prevent someone from listing directory contents,but allow access to a file in the directory if someone already knows it’s there.
  • chmod 777 
All permissions are wide open.
  • chmod 0000 
All permissions are closed. Good to protect a directory from errant changes.
However, backup programs that run as non-root may fail to back up the directory’s contents.
  • chmod 666 
Open read/write permissions completely on a file.
  • chmod 644 
Only the owner can change or delete the file, but all can view it.

The first 0 in the mode line can usually be dropped (so you can use 777 instead of 0777).
The -R option is a handy feature of the chmod command. With -R, you can
recursively change permissions of all files and directories starting from a
point in the file system. Here are some

examples:

$ sudo chmod -R 700 /tmp/test Open permission only to owner below /tmp/test
$ sudo chmod -R 000 /tmp/test Close all permissions below /tmp/test
$ sudo chmod -R a+rwx /tmp/test Open all permissions to all below /tmp/test

Friday, March 1, 2013

How to start Apache Tomcat or Jetty Server using maven plugin in remote debugger mode in Ubuntu/Linux

Debugging is one of major requirement of a software debugging process.To fix a bug developer may need to find the exact bug and fix it.Debugging provides efficient way to analyse the variables and execution path of the code.Apache tomcat and Jetty are two of well known server which act as a container for web applications.So debug a web application server need to start in debugger mode.Here simple steps to start tomcat in debugger mode.

In bash console of Ubuntu execute following arguments.

Apache tomcat debugging mode

export JPDA_ADDRESS=8000
export JPDA_TRANSPORT=dt_socket
bin/catalina.sh jpda start

Done!
User can remotely connect through the port 8000 for debug the application!


Jetty debugging mode

Jetty server can start through maven plugin.So in order to enable remote debugging in jetty user can follow the following way.
Just two steps.

step 1
export MAVEN_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE - Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"

step 2

mvn jetty:run

Done!

Server listen on port 8000 until debugging client connecting to the server.
Simple as that!

Thursday, February 28, 2013

How to change the currant user to different user in Ubuntu

When you working,sometimes you may need to change current user to some other user.Here the procedure you need to follow is simple.In bash console in Ubuntu

$ sudo su            (you need to enter the root password)
$ su - {username} 

example:

$ su - testuser

Done!



Wednesday, January 2, 2013

Windows Command Line (cmd) commands

Active Directory ADmodcmd Active Directory Bulk Modify

 CSVDE Import or Export Active Directory data 
 DSACLs Active Directory ACLs
 DSAdd Add items to active directory (user group computer) 
 DSGet View items in active directory (user group computer)
 DSQuery Search for items in active directory (user group computer)
 DSMod Modify items in active directory (user group computer)
 DSMove Move an Active directory Object
 DSRM Remove items from Active Directory

Batch Files

CALL Call one batch program from another• CHOICE Accept keyboard input to a batch file CLIP Copy STDIN to the Windows clipboard CLS Clear the screen• CMD Start a new CMD shell COLOR Change colors of the CMD window• DOSKEY Edit command line, recall commands, and create macros ECHO Display message on screen• ENDLOCAL End localisation of environment changes in a batch file• EVENTCREATE Add a message to the Windows event log EXIT Quit the current script/routine and set an errorlevel• FOR /F Loop command: against a set of files• FOR /F Loop command: against the results of another command• FOR Loop command: all options Files, Directory, List• GOTO Direct a batch program to jump to a labelled line• IF Conditionally perform a command• IFMEMBER Is the current user a member of a Workgroup LOGEVENT Write text to the event viewer LOGTIME Log the date and time in a file MAPISEND Send email from the command line MORE Display output, one screen at a time PAUSE Suspend processing of a batch file and display a message• PROMPT Change the command prompt• REM Record comments (remarks) in a batch file• RUN Start | RUN commands RUNAS Execute a program under a different user account SET Display, set, or remove session environment variables• SETLOCAL Control the visibility of environment variables• SETX Set environment variables SORT Sort input SHIFT Shift the position of batch file parameters• SLEEP Wait for x seconds START Start a program, command or batch file• TIMEOUT Delay processing of a batch file TITLE Set the window title for a CMD.EXE session• WAITFOR Wait for or send a signal WMIC WMI Commands :: Comment / Remark•

Disk Management

BOOTCFG Edit Windows boot settings BCDBOOT Create or repair a system partition BCDEDIT Manage Boot Configuration Data CONVERT Convert a FAT drive to NTFS CHKDSK Check Disk - check and repair disk problems CHKNTFS Check the NTFS file system DEFRAG Defragment hard drive DISKPART Disk Administration DISKSHADOW Volume Shadow Copy Service DriverQuery Display installed device drivers FORMAT Format a disk FREEDISK Check free disk space (in bytes) LABEL Edit a disk label MOUNTVOL Manage a volume mount point NTBACKUP Backup folders to tape SFC System File Checker VOL Display a disk label•

Files and Folders

ASSOC Change file extension associations• ASSOCIAT One step file association ATTRIB Change file attributes BITSADMIN Background Intelligent Transfer Service CACLS Change file permissions CD Change Directory - move to a specific Folder• CIPHER Encrypt or Decrypt files/folders COMP Compare the contents of two files or sets of files COMPACT Compress files or folders on an NTFS partition COMPRESS Compress individual files on an NTFS partition COPY Copy one or more files to another location• CSCcmd Client-side caching (Offline Files) DEL Delete one or more files• DELTREE Delete a folder and all subfolders DIR Display a list of files and folders• ERASE Delete one or more files• EXPAND Uncompress files EXTRACT Uncompress CAB files FC Compare two files FIND Search for a text string in a file FINDSTR Search for strings in files FORFILES Batch process multiple files FSUTIL File and Volume utilities FTP File Transfer Protocol FTYPE File extension file type associations• iCACLS Change file and folder permissions MD Create new folders• MOVE Move files from one folder to another• MKLINK Create a symbolic link (linkd) OPENFILES Query or display open files POPD Return to a previous directory saved by PUSHD• PsFile Show files opened remotely PUSHD Save and then change the current directory• QGREP Search file(s) for lines that match a given pattern RECOVER Recover a damaged file from a defective disk REN Rename a file or files• REPLACE Replace or update one file with another RD Delete folder(s)• RMTSHARE Share a folder or a printer ROBOCOPY Robust File and Folder Copy SHARE List or edit a file share or print share SHORTCUT Create a windows shortcut (.LNK file) SUBINACL Edit file and folder Permissions, Ownership and Domain TAKEOWN Take ownership of a file TOUCH Change file timestamps TREE Graphical display of folder structure TYPE Display the contents of a text file• WHERE Locate and display files in a directory tree WINDIFF Compare the contents of two files or sets of files XCACLS Change file and folder permissions XCOPY Copy files and folders

Group Policy/Windows Installer

DevCon Device Manager Command Line Utility GPRESULT Display Resultant Set of Policy information GPUPDATE Update Group Policy settings MSIEXEC Microsoft Windows Installer PsInfo List information about a system PsShutdown Shutdown or reboot a computer REGSVR32 Register or unregister a DLL SHUTDOWN Shutdown the computer SLMGR Software Licensing Management (Vista/2008) WUAUCLT Windows Update

Networking

ARP Address Resolution Protocol BROWSTAT Get domain, browser and PDC info DNSSTAT DNS Statistics GETMAC Display the Media Access Control (MAC) address IPCONFIG Configure IP NET Manage network resources NETDOM Domain Manager NETSH Configure Network Interfaces, Windows Firewall & Remote access NBTSTAT Display networking statistics (NetBIOS over TCP/IP) NETSTAT Display networking statistics (TCP/IP) NSLOOKUP Name server lookup PATHPING Trace route plus network latency and packet loss PsPing Measure network performance PING Test a network connection ROUTE Manipulate network routing tables TRACERT Trace route to a remote host

Processes

KILL Remove a program from memory PATH Display or set a search path for executable files• PsExec Execute process remotely PsKill Kill processes by name or process ID PsList List detailed information about processes PsGetSid Display the SID of a computer or a user PsSuspend Suspend processes SCHTASKS Schedule a command to run at a specific time SOON Schedule a command to run in the near future TASKLIST List running applications and services TASKKILL Remove a running process from memory TLIST Task list with full path

Printing

CON2PRT Connect or disconnect a Printer MODE Configure a system device PRINT Print a text file PRINTBRM Print queue Backup/Recovery PRNCNFG Display, configure or rename a printer PRNMNGR Add, delete, list printers set the default printer RUNDLL32 Run a DLL command (add/remove print connections)

Registry

REG Registry: Read, Set, Export, Delete keys and values REGEDIT Import or export registry settings REGINI Change Registry Permissions

Remote Desktop

CHANGE Change Terminal Server Session properties Query Process Display processes (TS/Remote Desktop) Query Session Display all sessions (TS/Remote Desktop) Query TermServer List all servers (TS/Remote Desktop) Query User Display user sessions (TS/Remote Desktop) MSTSC Terminal Server Connection (Remote Desktop Protocol) RASDIAL Manage RAS connections RASPHONE Manage RAS connections Reset Session - Delete a Remote Desktop Session TSSHUTDN Remotely shut down or reboot a terminal server WINRM Windows Remote Management WINRS Windows Remote Shell

Services

CASPOL Code Access Security Policy Tool. NETSVC Command-line Service Controller PORTQRY Display the status of ports and services PsService View and control services SC Service Control SCLIST Display Services

System Information

NOW Display the current Date and Time DATE Display or set the date• HELP Online Help LOGMAN Manage Performance Monitor MBSAcli Baseline Security Analyzer MEM Display memory usage MSINFO32 System Information NTRIGHTS Edit user account rights PERFMON Performance Monitor PsLogList Event log records SYSTEMINFO List system configuration TIME Display or set the system time• TypePerf Write performance data to a log file VER Display version information• VERIFY Verify that files have been saved• WINMSDP Windows system report WHOAMI Output the current UserName and domain

User Administration

ADDUSERS Add or list users to/from a CSV file CERTREQ Request certificate from a certification authority CleanMgr Automated cleanup of Temp files, recycle bin CON2PRT Connect or disconnect a Printer CMDKEY Manage stored usernames/passwords DELPROF Delete user profiles DIRUSE Display disk usage GLOBAL Display membership of global groups LOCAL Display membership of local groups LOGOFF Log a user off MOVEUSER Move a user from one domain to another MSG Send a message PERMS Show permissions for a user POWERCFG Configure power settings PsLoggedOn Who's logged on (locally or via resource sharing) PsPasswd Change account password SHOWGRPS List the Workgroups a user has joined SHOWMBRS List the Users who are members of a Workgroup SUBST Associate a path with a drive letter USRSTAT List domain usernames and last login Commands marked "•" are Internal commands only available within the CMD shell. All other commands (not marked with "•") are external commands. External commands may be used under the CMD shell, PowerShell, or directly from START-RUN. See also: An A-Z Index of the Windows CMD command line Microsoft Help pages: Windows XP - 2003 Server - 2008 Server

Tuesday, January 1, 2013

How to search files in Ubuntu/Linux


1. Basic file search syntax

Ubuntu is using find command for search files in the file system.Basic syntax of search is follow below style


find [path] [expression]
where path is the path is the based directory where search need to be begins.If user not specify a path then find command starts to search file based on the currant directory where the terminal points.User can specify many expressions along with search patterns and actions for achieve many purposes as describe below.

2. Finding A File Based On File name

Let say for instance user wants to find a file named as "mytext.txt" in users home directories. (Case sensitive search)

$ find /home -name ‘mytext.txt’
Let say for instance user want to find all text files which has ".txt" suffix in users home directories. (Case sensitive search)
$ find /home -name ‘*.txt’
Let say for instance user want to find all text files which contains a string named as "tex" in users home directories. Following command search each and every file whether file name contains "tex" string.(Case sensitive search)

$ find /home -name ‘*tex*’
If user wants to search for all *.txt and *.avi files then it can be specify as follows.(Case sensitive search)
$ find /home -name ‘*.mpg’ -o -name ‘*.avi’
Case insensitive searches can be achieved by using the -iname phrase with the find command.


$ find /home -iname ‘*.mpg’

3. Adding Some More Functions to Search

Searching a entire file system causes to return thousands of files for a given file name .When user need to efficiently search file , Linux systems offer to specify search parameters to reduce the number of files return for a particular search.I show some examples below to demonstrate the search conditions.

Find all "mpg" files where size of each file greater then 700MB


$ find /home/ -name ‘*.mpg’ -a -size +700M’
Find all "mpg" files which are modified within 15 days

$ find /home -name '*.mpg' -a -size +700M -mtime -15

4. Adding Some Actions

User is beneficial of searching files with conditions.But when user need something to do with the search files,Linux systems is capable of manipulating files along with the search.User may need to remove all files,move files ant etc which are output as search results.I have described below some actions which are perform on searched files.

Below command will search all "mpg" files which are modified within 15 days along with the size of each file is more than 700 MB and move it to new file location "/home/harsha/".


$ find /home/ -name ‘*.mpg’ -a -size +700M -mtime -15 -exec mv ‘{}’ /my/harsha/ \;
Note:The use of "{}" and \;(there should be a space before this)
‘{}’ matches the file that was found, while \; terminate the exec statement.

I mentioned only few ways of efficiently search a file in Ubuntu/Linux systems.But there are many conditions and actions can apply for a search.

Sunday, December 30, 2012

How to find the process ID of running process and kill a process in Ubuntu/Linux

Using PS Commands

PS Commands gives out information of currently running process with process IDs(PID).Easy way to find a PID of a process is to use PS commands.I have described full article about how to find process details along with process ids and how to kill a user specified process.

Listing all running processes in the system


Linux systems offer commands to list each and every process runs in the system
   
 Command:    ps -aux | less

 Output:




Finding a process by specifying a name

User is capable of finding the process id and the details of a process by specifying the process name along with the commands.This is one of advantage of pipe and filter architecture in the Ubuntu.In the output image the process details can be describe as follows.First line "harsha" is the owner of the process and the next "5914" is the process id of the process.For more details

    Command : ps -aux | grep {process name}
    
Example:
  • See all java process
$ ps -aux | grep java (This will list the all the java processes)
   Output:

Finding the process id of a process

     Command:  pidof {Process Name} 

     Example:
     
$ pidof  java
    Output:
     
    

Other important commands regarding processes in Ubuntu/Linux Systems 

  • process except those running as root
   $ ps -U root -u root -N
  • See process run by user harsha
       $ ps -u harsha                                                                                                                                                                                            

Kill a user specified process

At some movements user need to kill a process after identified required process id by using above methods.

Command: kill {process id} or kill -9 {process id}

Example:
  • Kill a process
    $ kill  3486
  • Kill a process forcefully(Sometimes force kill required for kill a processes which are not kill by normal kill command. "-9" is specify a forceful kill.
$ kill -9 3486

References



Saturday, December 29, 2012

How to change the theme of IntelliJ Idea 12

Intellij idea has announce latest version of their IDE for java development which come with theme call 'Dracula'.Changing the theme is very simple follow simple steps as listed in below



1. Ctrl+~

2. Switch Look and Feel

3. Choose any theme(You may prefer dracula)

4. Restart

Done!