Difference between revisions of "Ssh"

From Hackerspace ACKspace
Jump to: navigation, search
(ssh snippets. Tired of searching for them)
 
(No difference)

Latest revision as of 07:30, 12 October 2018

Zo. Zat van iedere keer te moeten pielen.. Alhier mijn online kladblok.. Waarschijnlijk ooit een volledig script..

# 1. create keyfile. Remove -N to use a password.
ssh-keygen -t rsa -b 4096 -N -CMyPuter -f.ssh/my.slurver.tld
# 2. enable password login
# as root on the server
sed -i -r 's/#?\s*(PasswordAuthentication\s+)no/\1yes/g' /etc/ssh/sshd_config
service ssh restart
# 3. upload keyfile
cat ~/.ssh/my.slurver.tld.pub | ssh me@my.slurver.tld "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys"
# 4. disable password login
# as root on the server
sed -i -r 's/#?\s*(PasswordAuthentication\s+)yes/\1no/g' /etc/ssh/sshd_config
service ssh restart
# 5. create an easy entry
echo "Host slurver" >> ~/.ssh/config
echo "Hostname my.slurver.tld" >> ~/.ssh/config
echo "User me" >> ~/.ssh/config
echo "IdentityFile ~/.ssh/my.slurver.tld" >> ~/.ssh/config
echo "DynamicForward 9999" >> ~/.ssh/config
echo "" >> ~/.ssh/config
chmod 600 ~/.ssh/config


# some ssh restart commands to try
sudo service ssh restart
sudo service sshd restart
sudo systemctl reload sshd.service

/etc/bash_completion.d/ssh Also see https://unix.stackexchange.com/questions/136351/autocomplete-server-names-for-ssh-and-scp

_ssh() 
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts=$(grep '^Host' ~/.ssh/config ~/.ssh/config.d/* 2>/dev/null | grep -v '[?*]' | cut -d ' ' -f 2-)

    COMPREPLY=( $(compgen -W "$opts" -- ${cur}) )
    return 0
}
complete -F _ssh ssh