The lead developer at Mosaic, Brighton with a passion for web application development and motorcycles.
External Link: Why won't ssh-agent save my unencrypted key for later use?
I recently was annoyed by always having to enter my private keys passphrase every time I wanted to do a git push to or pull from a public git repository. Turns out that if you are logged into a Gnome session on an Ubuntu machine it will automatically add you key to ssh-agent, but if you are logged into a bash session (as I was) then it won’t.
So you can either manually do the ssh-add yourself or following the instructions in the answer to my question you can setup an automatic way of facilitating this.
One problem I discovered is that if you have git displaying the current branch information in your bash prompt like me then when you start a session it will ask you for your passphrase before rendering your bash prompt.
I am thinking that to work around this I could change the git function in the .bash_profile file to look at the arguments passed to it and if it is a remote operation such as a pull, push or clone then trigger the ssh-add otherwise it can safely skip it.
Any other ideas or patches?
I use most of these commands every day to simplify my terminal interactions with an Ubuntu development box. This is more of a personal reference but thought I would share incase you find it useful.
| Task | Command |
|---|---|
| Get all users on the system |
|
| Delete all .svn or any file name by replacing .svn in the command with your filename | find ./ -name ".svn" | xargs rm -Rf |
| Look for enabled modules or particular environment settings in PHP |
for example |
| Push a line of text into a file |
to reset file content to ‘text to push’ – |
| Create an empty file | touch filename.ext |
| Watch a file on the command line. Useful for viewing logs whilst debugging. | tail -f /var/log/filename.extuse control + c to break |
| Break the current command | Use the keyboard combination control + c |
| Access to MySQL | Converting Microsoft Access MDB Into CSV Or MySQL In Linux |
This is not a post about setting up Samba shares. If that is what you are looking for then I can recommend the following book; Using Samba: A File & Print Server for Linux, Unix & Mac OS X.
Sometimes you need to be able to access a remote Samba server in a secure manner from a Windows machine. This is a relatively simple procedure on an XP SP3 machine like mine linking into an Ubuntu server pre setup with Samba file sharing.
Windows is a little bit annoying as it binds all filesharing operations to port 139 so you cannot have more than one filesharing system in operation at once. If you were to tunnel directly across to your Samba server it would bang heads with the Windows filesharing layer. You could just disable file sharing in Windows but that is an in elegant method and you may need access to both Windows and remote Samba shares. So we will need to setup a new loopback adapter with a local ip address that we can tunnel Samba request through thus allowing Windows filesharing to operate normally along side Samba. This effectively makes Windows think that it is accessing Samba shares on a seperate machine whereas a tunnel usually acts as a port on the local machine.
In the Run command console (Start > Run) enter ‘\10.0.0.1′ and you should be presented with file explorer window containing the contents of your Samba share.
So if that worked we are ready to roll, but you can give your Samba share ’server’ a more friendly name by opening ‘C:WINDOWSsystem32driversetchosts’ in your favourite editor (Vim in my case). Scroll to the bottom and enter the following ‘10.0.0.1 samba’. You can now access ‘//samba’ in the same way we did above via the Run dialogue. If you have assigned the loopback device to a different subnet then you will need use the lmhosts file in the same directory instead – please see Microsoft KB Article Q105997.
Now you can Map the Samba share like any other by using the ‘Tools’ menu in a Windows file explorer window. In the ‘Folder’ input enter ‘\samba’ or for a home directory called simon ‘\sambasimon’ (you must have enabled home directory sharing in your Samba smb.conf (/etc/samba/smb.conf)).
As you have found this page I am sure you have accidentally hit the control+s short cut whilst inside a PuTTY shell and following that no keystrokes appear to affect the session. Basically hitting ctrl+s causes PuTTY to stop executing the stream coming in from the keyboard. It does however still listen to your keystrokes and it basically adds them to a queue.
Hitting control+q will re-open the stream execution, but it is worthwhile noting that it will also execute all the queued up commands as well!
Certificates are a useful way of restricting access to your SSH server because a user must have three things to log onto the server:
Normally they would only need to have a password and username, which can be guess at or (potentially) brute forced. Forcing the user to supply a certificate on log on means that they must also have a tangible source of identification (without the key file they cannot log in!).
Log onto the server and run ssh-keygen and you will get asked a few questions as follows (enter a passphrase):
user@host$ sudo ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user/.ssh/id_rsa.
Your public key has been saved in /home/user/.ssh/id_rsa.pub.
The key fingerprint is:
95:60:c2:31:2e:94:cf:66:b6:fa:8b:b8:45:6c:dd:22 user@server
The key’s randomart image is:
+–[ RSA 2048]—-+
| .o+.o |
| ….+ . . |
| .o. o |
| . o*. . |
| E+o.S |
| o … |
| .. |
| o.. |
| o…o. |
+—————–+
This will generate two files:
in your home directory (if you chose the defaults). They are your private and public keys respectively. The public key is the one that goes on your server and the private key is the one you use when logging into the server.
Now on the server run
user@server:~$ cat id_rsa.pub » ~/.ssh/authorized_keys
user@server:~$ rm id_rsa
which adds the public key to the list of authorized keys for this user.
To edit the config run
user@server:~$ sudo vim /etc/ssh/sshd_config
Ensure that you have the following lines uncommented and set correctly in your configuration file:
RSAAuthentication yes
PubkeyAuthentication yes
If you wish to lock non-certified logins from the server then also ensure you activate the following settings:
ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM no
Now reload the SSH configuration to get the new settings going:
user@server:~$ sudo /etc/init.d/ssh reload
PuTTY has its own private key format and the private key you created earlier now needs to be converted, which is a very simple process. Firstly you need to download the key from the server and save it to your computer.
Now the new key we just saved is compatible with PuTTY we can start a new PuTTY session as usual, but don’t forget to tell PuTTY where the key file is located by looking in the Category tree menu and clicking on Connection -> SSH -> Auth. You can now click the “Browse” button and point PuTTY to the key file you just created.
Click open and a new session will load:
A very nice article: Keeping SSH access secure
I use the following in /etc/ssh/sshd_config:
AllowUsers username
PermitRootLogin no
Which kills root login access to the server meaning you will need to login as the username provided in AllowUsers and then su to root (eg. su root) or sudo the commands if you have sudo setup (apt-get install sudo).
You may also wish to change the port through which SSH occurs by adding:
Port 2345
Where 2345 is the new port number. This will stop people from attacking through the standard port 22, which can help against script kiddies and those using pre-packaged scripts. It will however not stop someone from finding the new port via ICMP sweeps.
Kick over SSHd:
/etc/init.d/ssh restart