Deleting multiple files with one command

I’ve encountered many times the need to remove multiple files where the “rm” command didn’t work.

For example when you have a temporal directory with “to many files” the remove command (rm) does NOT work

I fixed it with this one:

find . -name “.._.fstemp*” -exec rm -rf {} ;

Use ssh as a proxy server

Using ssh as a proxy or encrypted tunnel to browse the web can sometimes be necessary:

  1. When you’re at a conference but need to login securely to your blog.
  2. When local access restrictions make life really difficult.
  3. If you have a server in another country and want to see what Google Adsense adverts people see in that country.

ssh -D 8181 -Nf  example.com

ssh -D 8181 -Nf  yourlogin@example.com

Where example.com is the name of the site you are connecting to (ssh) and 8181 is the port you’ll use in your browser.

You’ll use the first option if you have set up your connection without password, otherwise use the second option

Then configure your browser to user Proxy at: localhost:8181 (or 127.0.0.0:8181)

Here’s an example of how to configure the proxy on Mac

Mac's Proxy setup

Enjoy.

SSH Without Password

 

Sometimes we need a ssh connection that do not ask for passwords. It is use frequently in scripts that involve ssh, scp or sftp connections. 

So, those are the steps to make such connection.

1. Login as user1 on computer1 and generate a pair of authentication keys. Note: even if is unsecured to work without password, do not enter it. Let it empty…

[user1@computer1]$ ssh-keygen -t rsa 
Generating public/private rsa key pair. 
Enter file in which to save the key (/home/user1/.ssh/id_rsa): 
Created directory ‘/home/user1/.ssh’. 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/user1/.ssh/id_rsa. 
Your public key has been saved in /home/user1/.ssh/id_rsa.pub. 
The key fingerprint is: 
31:df:a5:73:4a:2f:a6:6c:1c:32:a2:f2:b3:c5:a7:1f user1@computer1

2. Login to the remote computer (computer2) as user2 and create the .ssh directory (many Linux distributions create this folder by default. No problem with that.). You still need the password for now…

[user1@computer1]$ ssh -l user2 computer2 mkdir -p .ssh 
user2@computer2’s password:

3. Copy the user1 public key to user2@computer2 .ssh folder into authorized_keys file. And, type the password again for the last time, hopefully…

[user1@computer1]$ cat .ssh/id_rsa.pub | ssh -l user2 computer2  
>’cat >> .ssh/authorized_keys’ 
user2@computer2’s password:

4. If all things are OK, you don’t need the password

[user1@computer1]$ ssh -l user2 computer2 
[user2@computer2]$

..or optionaly (see the troubleshooting section of this page): 

[user1@computer1]$ ssh -i $HOME/.ssh/id_rsa user2@computer2

 

NOTE:
This is the way not only for ssh but also for scp and sftp as well…

TROUBLESHOOTING:
If the password prompt will be shown again check the /etc/ssh/ssh_config and uncomment or insert the following option:

IdentityFile ~/.ssh/id_rsa

As you can see, the above option is for RSA type keys. If you want to generate the key pairs using DSA change the “id_rsa” with “id_dsa”. Sound logic, right? 
This modification in /etc/ssh/ssh_config file can be avoided if you will use the parameter “-i” followed by the location of the key file as in example: 

[user1@computer1]$ ssh -i $HOME/.ssh/id_rsa user2@computer2

 
Also, if you do have write permissions for either the .ssh directory or for the authorized_keys file on the remote machine, then sshd will consider that the procedure is not safe enough, so it will abort the RSA challenge-authentication mode (mode 3) and will go to the default mode (mode 5) asking you for the password on the remote machine. Set chmod 700 for .ssh folder and 600 authorized_keys file.