Showing posts with label ssh. Show all posts
Showing posts with label ssh. Show all posts

Saturday, May 7, 2011

Ssh execute remote commands

Ssh is a very very useful tool and some tricks with it will help you a lot of time and typing. For example I want to transfer a file remote like my ssh-key file. I have a few options:

  • use scp to transfer the file, then login into the remote system and execute the commands.
  • use a different mechanism to transfer the files(ftp etc), login and execute the commands.
  • do it all in one command ... this is the cool one - see bellow


shell$ cat ~sd/.ssh/id_rsa.pub | ssh root@192.168.0.105 'cat - > .ssh/authorized_keys'
shell$ cat ~sd/.ssh/id_rsa.pub | ssh root@192.168.0.105 'cat - > .ssh/authorized_keys2'

# usually the authorized_keys is a link to authorized_keys2 but in this I just have two separate files.
# as you can see is nothing else to do :)


Tuesday, December 14, 2010

Remote mount trough ssh - sshfs

You may need to work on remote hosts file systems and copying files over with scp/sftp may be a hassle. This is why sshfs is in place - you can mount remote file systems locally on your computer


How to do it (on ubuntu) - install first the sshfs


$ sudo aptitude install sshfs
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
The following NEW packages will be installed:
  sshfs
0 packages upgraded, 1 newly installed, 0 to remove and 6 not upgraded.
Need to get 40.8kB of archives. After unpacking 143kB will be used.
Writing extended state information... Done
Get:1 http://ca.archive.ubuntu.com/ubuntu/ lucid/main sshfs 2.2-1build1 [40.8kB]
Fetched 40.8kB in 0s (44.3kB/s)
Selecting previously deselected package sshfs.
(Reading database ... 197354 files and directories currently installed.)
Unpacking sshfs (from .../sshfs_2.2-1build1_i386.deb) ...
Processing triggers for man-db ...
Setting up sshfs (2.2-1build1) ...
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
Writing extended state information... Done


then is as easy as

$ mkdir /tmp/remote_host_name_yours
$ sshfs your_remote_host: /tmp/remote_host_name_yours
$ cd /tmp/remote_host_name_yours

that is it ! (you may be need to input a password or paraphrase)
to umount the remote file system you need to use


$ fusermount -u /tmp/remote_host_name_yours


for more info see http://fuse.sourceforge.net/sshfs.html

Monday, August 17, 2009

ssh-agent(ssh-add) from X under Gnome and CentOS5

Ok you connect to multiple servers and want NOT to type your very secret passphrase every time you
connect to a server.
If you use any type of X window manager is very easy to use a the file

$HOME/.xinitrc in which you have the following

exec ssh-agent

Then after you login into GNOME/KDE etc open a xterm, kterm or any other xterminal and type
ssh-add - you will be prompted to input your secret passphrase.

Be aware that if you don't have any type of keys into your $HOME/.ssh then all the above won't work
because ssh-add needs to have some keys to work with.

In case you need to generate keys is simple:

open a shell

$ssh-keygen -t rsa -b 1024 -- will make you a rsa key 1024 bits
$ssh-keygen -t dsa -b 1024 -- will make you a dsa key 1024 bits