sudo please

I stumbled across this alias quite a few months ago, but it was under a different name then.

I wanted to find it today and Google searches brought up a whole heap of malicious finds on it, aimed at targeting the unsuspecting newbie to linux. Obviously there are some very dangerous linux commands and so I’m not going to repost them here. Or maybe.

In linux, when you need special permissions to run a command, you’ll get a “permission denied” error. The standard response to that is to “sudo !!” (pron: sudo bang bang) which runs the last command again. Everyone who’s ever used linux will know this can get frustrating.

The I found “fuckit” (or it could have been just “fuck”, I can’t remember which).

When you forget to type sudo, and you’re prompted your permission has been denied, you can issue the expletive whereby the command runs as expected. The funny thing about this, is that when this does happen, it is the sort of thing you are probably thinking, and the expletive does it’s job.

In looking for it today, I found that someone else uses the “please” alias instead. There’s no difference, they both do the same job. It’s just how you feel you want to talk (type) to your computer at the time.

To achieve this, you need to create an alias:

alias please='sudo $(fc -ln -1)'
alias fuck=please

Only include the second line if you feel so inclined. I did because initially you can be all like “please?? Oh thank you understanding computer.” but after a day of permission denied errors, you might be more inclined to just yell at the screen, in which case, the second line is more appropriate.

Creating the alias alone won’t make it persistent. To do that, add the alias to the end of your ~/.bashrc file, or in my case, I’m running ubuntu and you can add it to ~/.bash_aliases instead.

Ubuntu – changing DHCP to Static

Before jumping in and making the changes, do
ifconfig -a
and note down any particular settings which you may need (if you don’t already know them)

Then edit /etc/network/interfaces

change:

iface eth0 inet dhcp

to:

iface eth0 inet static
address 10.0.0.101
netmask 255.255.255.0
network 10.0.0.0
broadcast 10.0.0.255
gateway 10.0.0.100

May also need to add nameservers to /etc/resolv.conf, eg:
nameserver 10.0.0.100
nameserver 192.122.108.211

Obviously change to suit your network settings.

Once done, don’t forget to restart the networking interface

sudo /etc/init.d/networking restart

Synergy in OpenSolaris and Ubuntu

I have been tinkering with linux distros for a while now, my favourite (generally) would have to be Ubuntu. It is one of the few that installs quickly and simply on most of my systems here.

A package I also use is Synergy. This is one of the best pieces of software ever developed for multi-desktop computing. Much better than VNC and Remote Desktop, although they each serve their purpose and offer different functionality.

To learn more about Synergy, visit http://synergy2.sourceforge.net/

To learn how to install it in OpenSolaris (I am using preview 2) it is simply a matter of:
wget ftp://ftp.sunfreeware.com/pub/freeware/intel/10/libgcc-3.4.6-sol10-x86-l...
gunzip libgcc-3.4.6-sol10-x86-local.gz
pkgadd -G -d libgcc-3.4.6-sol10-x86-local
wget ftp://ftp.sunfreeware.com/pub/freeware/intel/10/synergy-1.3.1-sol10-x86-...
gunzip synergy-1.3.1-sol10-x86-local.gz
pkgadd -G -d synergy-1.3.1-sol10-x86-local

You have to make sure that /usr/local/bin is in your path.

tip: I use/prefer BASH, to edit the user path for BASH in OpenSolaris you HAVE to edit the file .bashrc located in your home directory. Editing it anywhere else will have no effect since (in Preview 2) this file explicitly defines the path WITHOUT inheriting the original path. You have been warned (it took me a few hours to find this!)

for ubuntu there is an excellent walkthru here: https://help.ubuntu.com/community/SynergyHowto

note: for the ubuntu install, make sure you have added the universe repositories http://dav3.net/ubuntu/repositories

Adding Ubuntu Repositories

In a nutshell
edit the file /etc/apt/sources.list

You can edit it from the command line ( http://help.ubuntu.com/community/Repositories/CommandLine ) or use the GUI from the Ubuntu desktop: System –> Administration –> Software Properties and add to the repositories by adding a channel (the add button). You can also add new repositories there as well.

For a very well documented HOWTO: visit http://help.ubuntu.com/community/Repositories/Ubuntu

SSH Server in Ubuntu

To securely administer your Ubuntu Server remotely, you need to install SSH server. SSH provides you with a secure connection to your server and allows you to run commands all as if you were logged in at the terminal itself.

To install SSH server in Ubuntu
$ sudo apt-get install openssh-server

All going well, your install is complete. your RSA and DSA keys have been created and you have a default config file.

Connecting to the server
To connect to the server from other machines use ssh (on *nix computers or putty on windows systems). You log into the machine by typing:

$ ssh 192.168.0.4 or c:\>putty 192.168.0.4
(this is an example IP address, use whatever IP address is assigned to the server)

Configuring SSH
There is a default config already with the SSH Server, you can chop and change it to suit your needs. For security you may want to disable root logins and X11Forwarding. If you don’t know what they are, then you probably do want to disable them anyway. The configuration file you want to edit is /etc/ssh/sshd_config

Disable remorte root logins
Search for and edit the following line in the /etc/ssh/sshd_config file:

PermitRootLogin yes
and change it to:
PermitRootLogin no

Disable X11 forwarding
Same file as above, search for and change the following line:

X11Forwarding yes
to:
X11Forwarding no

Restart the SSH Server
After you have made these changes, you will need to restart the SSH server. At the command prompt type:
$ sudo /etc/init.d/ssh restart

More on X11 Forwarding
If you want to use X11 Forwarding option so that you can connect your remote machine desktop using Xterm if you want to connect the X11 session you need to use the following command

ssh -X serveripaddress

Copy Files Securely using SCP
Another common need is to be able to copy files between servers you are administering. While you could set up FTP on all of the servers, this is a less-than-ideal and potentially insecure solution. SSH includes within it the capability to copy files using the scp command. This has the added benefit of copying the files over a secure channel along with taking advantage of any key-based authentication you might have already set up.

To copy a file to a remote machine use the following command

scp /path/to/file user@remotehost:/path/to/destination

If you need to copy from the remote host to the local host, reverse the above command

scp user@remotehost:/path/to/file /path/to/destination

if you need to copy an entire directory full of files to a remote location, use the -r argument

scp -r /path/to/directory/ user@remotehost:/path/to/destination/

If you are transferring logfiles or other highly compressible files, you might benefit from the -C argument. This turns on compression, which, while it will increase the CPU usage during the copy, should also increase the speed in which the file transfers.

Use the -l argument to limit how much bandwidth is used. Follow -l with the bandwidth you want to use in kilobits per second. So, to transfer a file and limit it to 256 Kbps use the following command

scp -l 256 /path/to/file user@remotehost:/path/to/destination

RAR in Ubuntu

IMHO RAR is a dying archive format, except in the torrent and related warez world. Why? I don’t know. But what I do know (now) is how to install RAR for linux under Ubuntu 6.10 (Edgy) and this is it:

Download rarlinux, the version I got was 3.6.0 and I found it here:

http://www.rarlab.com/rar/rarlinux-3.6.0.tar.gz

(you can use ‘wget’ from a linux console to grab it)

ungzip the file:

tar -zxvf  rarlinux-3.6.0.tar.gz

Now for some reason when i did this the first time, it didn’t fully unzip and I had to process the tar file again, but on another machine both steps were done with the above command. If you have a rar folder now, then skip the next command, but if you have a new file with the name rarlinux-3.6.0.tar (ie, no .gz ext) then untar it with the following:

tar -xvf rarlinux-3.6.0.tar

then change into the rar directory created, and you only need to copy the ‘rar’ file into your “/user/bin” directory

cd rar
cp rar /user/bin/.

use “rar” at the command line without any options to get an overview of the switches and commands associated with it