Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Tuesday, March 24, 2015

texshop 日本語入力

texshopで背景色を黒にしている場合,日本語入力がまだ未確定の場合,入力している文字が見えなくなるという問題がある.これは良くするためには次のコマンドを使えば良い.

defaults write TeXShop ResetSourceTextColorEachTime YES

しかし,これでバグがでることもあるようなので注意.

参照:
http://pages.uoregon.edu/koch/texshop/version.html

Wednesday, July 30, 2014

Bitbucket with SSH

If you want to access bitbucket via SSH instead of https, upload the SSH RSA public key to bitbucket. Then use the following path for example when cloning.

git clone ssh://git@bitbucket.org/Bollegala/SupEmb.git

Thursday, February 28, 2013

tmux

  • Commands:
    • starting a new named session
      • $ tmux new -s session_name
  • you can use a .tmux.conf file in your home directory to tmux as follows
    • setw -g mode-mouse on
    • # scrollback buffer size increase
    • set -g history-limit 500000
  • note that with mode-mouse on you cannot copy paste text (you can scroll). You need to do the following Ctrl+B: (note the colon) and then enter the following command
    set -g mode-mouse off
  • when you have finished copy/pasting text you can turn mode-mouse to on so that you can scroll using the mouse wheel

Sunday, September 30, 2012

git (using gitosis)

gitosis is a great way to have a private git server. To install gitosis and perform the basic configurations refer to this guide. gitosis can use ssh access to your remote repositories. Unlike svn (and many other version control systems), git keeps an entire snapshot for your commits instead of a series of diffs. This is great because you can see the entire history of your project locally and develop locally. This comes handy when you do not have access to the internet to push your commits to the remote repository. Moreover, even in the event that the remote repository dies, you can still recover your code using your local database. For this and many other reasons (such as the distributed mirroring and the free github), git is the most popular choice for version control.


Installing gitosis in your remote server

Once you have installed gitosis in your remote server, you must clone gitosis-admin repository to your local machine. You can perform numerous administrative tasks locally via this repository such as adding new projects.

The first time you use git to push something you must specify your name and e-mail address. This can be done as follows.

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

To add a new repository do as explained here.

  1. cd gitosis-admin
  2. git pull   This will update your gitosis-admin repository
  3. If you do not have your gitosis-admin repository, then you must first clone it by
    git clone gitosis@server:gitosis-admin.git
  4. Now edit the gitosis.conf file and add your newproject details
    [group helloproject]
    members = mylogin@myhost
    writable = helloproject
    Note that the last one is "writable" and not "writeable"
  5. Now commit the changes you made to gitosis-admin repository by,
    git commit -am "added the project helloproject"
    next push the commit to the local db by git push
  6. Now move to the directory that contains files for your new project "helloproject". Then do git init
  7. This will initialize the new repository. You can add individual files to track using
    git add filename
    You cannot add an empty directory to git repository. When you add a file from a directory that directory will be automatically added to the repository. However, if you want to add an empty directory to the repository you can either place a dummy README file in that directory or write a .gitignore file in the directory that you want to add. The .gitignore directory must contain the following two lines.
    # Add everything in this direcory
    *
    # Except for this file.
    !.gitignore
  8. Once you have added the files for the newly created helloproject you must commit them.
    git commit -am "Initial commit for helloproject"
  9. Now you need to add this new project to your remote repository by
    git remote add origin ssh://gitosis@myserver/helloproject.git
  10. You can now push the changes to your remote repository
    git push --all
  11. In order to be able to pull back to the same directory (without cloning the pushed project from the remote server) you must edit .git/config file as follows.
    [branch "master"]
    remote = origin
    merge = refs/heads/master
  12. That is it.
Git development cycle (command used frequently)
  1. You would either add an existing project to git as explained above or will clone a project from the remote repository. To clone do as follows.
    git clone gitosis@myserver:helloproject.git
  2. Now you will modify some tracked files and/or add new files to be tracked using
    git add filename
  3. Note that there is this concept of staging in git which means you must first "stage" files to be committed and then perform the actual committing. This means you will have to add again any files that you have modified in order for them to get committed. This additional staging step can be skipped by using the -a option during commit.
    git commit -am "message"
  4. Commit actually commit things to your local repository. It does not push your changes to your remote server. To push your changes to the server do as follows.
    git push
  5. This is the basic (frequent) development cycle. Note that if someone else have pushed before you (i.e. origin has been modified by some other person other than you), then git push will fail. You must first git pull their changes and then check them with your modifications (git fetch will not merge but git pull will try to merge) and then git push again.
Git useful tricks
  1. Use git status to see what are the changes that are going to be committed in the next commit.
  2. You can use tags to easily refer (and checkout) important milestones of your project.
    To list the current tags do
    git tag -l
  3. To create a new tag do as follows
    git tag -a v1.0 -m "first version"
  4. To push your tags to the remote server do,
    git push origin v1.0
  5. Now when someone clones this repository that person will also receive the tag v1.0. After cloning a project you can checkout a specific tag as follows.
    git checkout v1.0
  6. If we want to delete the tag see here.
Git hub
  • cloning a repository from github
    • git clone git://github.com/Bollegala/svdmi.git
  • You might not be able to push to the original git directory if you have not set the git url as follows
    • git remote set-url origin git@github.com:Bollegala/svdmi.git 
 


Saturday, September 29, 2012

fish shell vs. bash

fish shell is a great tool. But it can be confusing in the initial stages especially to adapt from bash to fish shell. Some important differences are highlighted below.


  1. escaping wildcards such as *
    use double quotes
    rm "*.pyc"
  2. command expansion using backticks
    the bash command
    rm `find -type d -name .svn` would be
    rm (find -type d -name .svn) in fish shell

Friday, July 8, 2011

Synchronizing system clock (Ubuntu)

There are nice GUIs to do this if you have installed some Window managing system such as Gnome or KDE. However, if you have a server installation and have not installed any of those Window managing system and/or want to do this via command line then do the following (requires sudo access).


sudo ntpdate ntp.ubuntu.com

Saturday, November 27, 2010

Compressing and Decompressing Files

To decompress tar.gz (tgz) do (tar combines multiple files in a directory to a single file and gz compresses it)
  • tar xzvf filename
To compress to tar.gz do
  • tar czvf filename.tgz directory/
To decompress bz2 files do
  • bunzip2 filename.bz2
  • if it is tar.bz2 then do tar -xjvf filename.tar.bz2
To compress into tar.bz2 do
  • tar cjvf filename.tar.bz2 directory/

Thursday, September 2, 2010

bash script to convert encoding of all files in a directory

The following bash script calls iconv on each text file in the input directory and converts them from shift-jis (sjis) to Unicode UTF-8 (utf-8).


#! /bin/bash

inputDir="danu-summaries"
outputDir="danu"

for file in ../$inputDir/*; do
    if [ -f $file ]; then
fname=`echo "$file" | cut -d '/' -f3`
echo $fname
iconv -f sjis -t utf-8 ../$inputDir/$fname > ./$outputDir/$fname
    fi
done

Tuesday, October 6, 2009

checking version

In RedHat Linux you can check the OS version by
cat /etc/redhat-release

to check the kernel type
uname -m
if it is 32bit you will see i386
if it is 64bit you will see x86_64

Saturday, July 11, 2009

basic authentication

If you want to provide basic authentication to a folder on your web server, do the following.

1. create a password file
htpasswd -c mypasswdfile username

Now enter a new password. If this file already exists then you do not need to create it by "-c".
Instead you can straight away add to the existing file a new username and a passwd.

2. Setting access.
cd to the folder that you want to protect and create a .htaccess file.
Add the following lines there.

AuthType Basic
AuthName authentication name
AuthUserFile location_of_the_mypasswd_file
AuthGroupFile ifany
Require specific_users can be given by user or set to valid-user

Thats all folks!

Sunday, June 28, 2009

firefox proxy

To connect to a remote computer and use it as a proxy do the following.

Open Tools->Options->Advanced->Network
SOCKS Host 127.0.0.1 Port 8080
select SOCKS v5

Now open a tunnel in Cygwin+Poderosa by
ssh -C2qTnN -D 8080 usernam@server

Alternatively, you can do the same using Putty.
For this set up a putty connection with details like host, auto login name etc.
Then load your private key to the server in the pagent.
Now to create the tunnel in putty,
Connection->SSH->Tunnels
In the source port type 8080
select Auto and Dynamic and hit Add.
This will add D8080
Now save those settings and open the connection.

Thursday, October 30, 2008

SAMBA Ubuntu Putty Windows Xp Tunneling Map Drive!

The objective is to access Ubuntu server from Windows Xp over internet using SSH!

To achieve this goal, this post describes the following:

1. How to install/configure SAMBA on Ubuntu (file server)
2. How to install/configure a network adapater on windows (Windows connection)
3. How to install/configure Putty (SSH agent)
4. How to Map a network drive (Mapping a network drive)

Installing SAMBA on Ubuntu
sudo apt-get update
sudo apt-get install samba

sudo emacs -nw /etc/samba/smb.conf [open config file]
set the following line.
browsable = yes
writeable = yes

restart samba
sudo /etc/init.d/samba reload

share a folder.
right click the folder in nautilus and select "share options"...share over windows networks (SMB)

see this video and this site

Install a loopback network adapter

A loopback network adapter is kind of a “virtual network adapter”: it acts as a normal network adapter, but you don’t have to install any physical hardware to use it. It is only usable on the PC it’s installed on (other PCs can’t connect to it).

  1. Go to Control Panel - Add Hardware
  2. Click Next, then wait a while, choose “Yes, I have already connected to the hardware” and Next again.
  3. Choose the last option, “Add a new hardware device”, click Next.
  4. Choose “Install the hardware that I manually select from a list (Advanced)”, click Next.
  5. Choose “Network adapters”, click Next.
  6. Choose Microsoft, “Microsoft Loopback Adapter”, click Next and Next again.
  7. Click Finish.

Configure the Microsoft Loopback Adapter

Since the loopback adapter won’t have a DHCP server to ask for an IP address, we need to configure an IP address manually.

  1. Right click on “My Network Places” (on your desktop or in your Start Menu), click Properties.
  2. Find the network connection that is associated with the “Microsoft Loopback Adapter”. Usually it’s called “Local Area Connection 2″. For clarity, I renamed mine to “Loopback” (what’s in a name?). Right click the connection name, click Rename and change it.
  3. Right click the Loopback connection, click Properties.
  4. On the General tab: disable “Client for Microsoft Networks” and “File and Printer Sharing for Microsoft Networks” (only untick the checkboxes, DO NOT uninstall!).
  5. Click “Internet Protocol (TCP/IP)” and click Properties.
  6. On the General tab: click “Use the following IP address” and pick a private IP address on an unused subnet (I used 192.168.100.100 with subnet mask 255.255.255.0).
  7. Click Advanced.
  8. On the WINS tab: click “Disable NetBIOS over TCP/IP”, then click OK and again OK.
  9. Click Close.

Create or edit the LMHOSTS file

  1. Open the file “C:\WINDOWS\system32\drivers\etc\lmhosts” (create it if it doesn’t exist - note that the file should have no file extension).
  2. Add the following line to the end of the file:
    192.168.100.100 servernamehere
  3. Save and close.

Configure PuTTY

At last, we have to tell PuTTY to create an SSH tunnel from the loopback connection to our home server. I assume you already have a PuTTY saved session to connect to your home server.

  1. Open PuTTY, click your saved session and click Load.
  2. Go to Connection - SSH - Tunnels.
  3. In Source port, type “192.168.100.100:139″ (I know, the field is quite small, but it will accept the value anyway).
  4. In Destination, type “localhost:139″.
  5. Click Add, and do not forget to resave your saved connection!

To confirm that everything is working, connect to your home server with the saved session in PuTTY. Click Start - Run and enter “\\servernamehere\sharenamehere”. Depending on your Samba setup, you may have to enter a username and password. Done!

Background information a.k.a. Frequently Asked Questions

Why do I have to install an extra loopback adapter? Can’t I use the adapter that’s already in my PC?

Yes, in fact you could use the adapter that’s already in your PC. But… you would still have to disable the Client for Microsoft Networks and File and Printer Sharing. That means you won’t be able to use any other shares besides your home shares. Not very practical. An extra adapter allows you to have Microsoft Networking enabled on your normal network connection and use your home shares simultaneously with other (work, school, …) shares.

Do I really need the LMHOSTS file?

No, you don’t. You could refer to the IP address as well (e.g. connect to “\\192.168.100.100\sharenamehere”). But I wanted the solution to be transparant, whether I’m at home or not. If I use “\\servernamehere\sharenamehere” at home, then I want to use it anywhere else as well (or else I have to remember too many things). That’s what the LMHOSTS file is for.

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

Above post was copied from here just in case the original post get vanished!

To set putty access without passwords, copy your private key (id_dsa) from the remote machine to the local machine. Open puttygen and load this key. Save this key in putty format without a passphrase. In Putty select ssh->auth and specify this file. Also connection->auto-login name and specify the user.


Thursday, October 16, 2008

subversion

[QUICK REF]

svn import -m "initial import" module svn+ssh://user@server/home/svn/repos/module/

svn co svn+ssh://user@server/home/svn/repos/module/ module

Refer this article to install subversion on Ubuntu and set up Apache to get web access to the repository. Following is a summary of the commands.
(using aptitude is better than apt-get because the former keeps a track of dependencies during uninstall time, and records a log)

installing subversion
sudo apt-get update
sudo apt-get install subversion

creating the repository
cd /var
sudo mkdir svn
sudo svnadmin create /var/svn/repos

add svn as a user
sudo adduser svn
sudo chown -R svn.svn svn

let a user access svn (add to svn group)
sudo vigr
admin:x:110:user_name
svn:x:1001:user_name

SSH access
sudo apt-get install openssh-server
svn co svn+ssh://username@machinename/var/svn/repos

chmod 0700 .ssh
chmod 0600 .ssh/authorized_keys2

Set up Apache Web Access to the repository
sudo apt-get install libapache2-svn
cd /etc/apache2/sites-enabled
sudo vi 000-default

<Location /svn> 
DAV svn
SVNPath /var/svn/repos
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/passwords
<LimitExcept GET PROPFIND OPTIONS REPORT>
Require valid-user
</LimitExcept>
<Location\>   
sudo /etc/init.d/apache2 force-reload

Add the following to the Location directive above to secure the repository.
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/passwords
Require valid-user

set up BASIC authentication as follows.
sudo htpasswd -cb /etc/apache2/passwords USERNAME PASSWD

sudo /etc/init.d/apache2 force-reload

To see whats on SVN do a list:
svn list svn+ssh://user@server/home/svn/repos

Tortoise SVN
This tool provides a shell script in Windows explorer so that we can easily
checkout, import, or update a folder with an SVN repository in a remote machine.
I will describe how to use Tortoise with svn+ssh on Windows using Putty.

download and install tortoise from here.
http://tortoisesvn.tigris.org/
Installation is fairly simple. Requires a restart on Xp after installation.
Create a tunnel using putty.
First create a key using putty keygen. You can either convert an existing private
key or create a private/public key pair from the scratch by doodling some random
movements. Now load the private key by double clicking. This should load they key
to putty agent and the agent should appear as an icon in the Windows system tray.
Now open putty and create an SSH connection to the remote server as follows:
Give the HOST name (alternatively the IP), specify a name in the saved sessions box,
in the connection->Data provide your username in the "Auto-login username".
Now save the session, load it and open it. Now right click on any windows explorer
window (in a directory) and in the pop-up menu select TortoiseSVN->Repo-broweser and
type the following the url box:
svn+ssh://username@server/home/svn/repos

This will show you all the modules uploaded to the SVN server.
If you are in Linux, then when you try to use svn+ssh then it will always ask you to
type your password. To avoid doing this add your id_dsa.pub and/or id_rsa.pub public
keys to authorized_keys and authorized_keys2 files by doing
cat id_rsa.pub >> authorized_keys2


Thursday, October 2, 2008

Linux Networking

To specify a DNS server:

/etc/resolv.conf
nameserver XXX.XXX.XXX.XXX

Saturday, August 16, 2008

ssh keys and permissions

create ssh keys in your local machine (if you don't have any yet)
ssh-keygen -t rsa

This will create two keys id_rsa and id_rsa.pub

In the remote machine, create a .ssh directory in your home directory
set permission to 700 by, chmod 700 .ssh

create an authorized_keys file in the .ssh directory by
touch authorized_keys

copy the public key into this file by,
cat id_rsa.pub >> authorized_keys

set the permission of authorized_keys to 640
Now you can access the remote machine without passwords!

Friday, July 11, 2008

screen command

to switch off the startup message in the screen command,

sudo emacs -nw /etc/screenrc
and uncomment the line,
startup_message off

to enable scroll mode do Ctrl+A and ESC
Press ESC to return to normal mode.

To reattach a screen that is attached else where do:
screen -d

The following commands can be used for navigation purposes. Reference


h -    Move the cursor left by one character
j -    Move the cursor down by one line
k -    Move the cursor up by one line
l -    Move the cursor right by one character
0 -    Move to the beginning of the current line
$ -    Move to the end of the current line.
G -    Moves to the specified line 
       (defaults to the end of the buffer).
C-u -  Scrolls a half page up.
C-b -  Scrolls a full page up.
C-d -  Scrolls a half page down.
C-f -  Scrolls the full page down.
By writing the following line to .screenrc in $HOME you can change number of lines that are stored in the scrolling buffer.

defscrollback 5000

Enable mouse wheel in Ubuntu VMWare guest

If you are using guest Ubuntu under VMware, mouse scroll does not work.
To fix this, open terminal and type the following:
$ sudo gedit /etc/X11/xorg.conf
Then find "InputDevice" section with Identifier "Configured Mouse"
Change Option "Protocol" "ps/2"
to
Option Option "Protocol" "IMPS/2"
Last restart X using Ctrl + Alt + Backspace

Thursday, July 10, 2008

suppress the log-in message

create a file on the remote machine by,
touch .hushlogin

Symbolic links

ln -s /data/dvd5 dvd5
If dvd5 is a directory then we must create a soft link using -s option.
Do not use a trailing back slash after the directory name

firefox remote

to open firefox on a remote machine, in that local machine do;

firefox -no-remote&
If there is already a firefox opened in the remote machine then you
will have to first close it.
find the pid of the currently running instance of firefox by,
ps -ax|grep 'firefox'
and kill it by
kill -9 pid

Continuously monitor GPU usage

 For nvidia GPUs do the follwing: nvidia-smi -l 1