post edit button on front end

The function is edit_post_link() (see Codex or source). In TwentyEleven it used as follows in content.php

edit_post_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' );

You can simply use the function as indicated above (or in the Codex) in a custom template, but it must be used inside the loop. There’s no need to perform any permission checks.