17 lines
		
	
	
		
			479 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			17 lines
		
	
	
		
			479 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
#!/bin/sh
 | 
						|
 | 
						|
[ -n "$1" ] && login=$1 || read -p "provide login: " login
 | 
						|
[ -n "$2" ] && ssh_key=$2 || read -p "provide ssh key: " ssh_key
 | 
						|
 | 
						|
ssh_dir=/home/$login/.ssh
 | 
						|
mkdir -p "$ssh_dir"
 | 
						|
[ ! -f "$ssh_dir/authorized_keys" ] && touch $ssh_dir/authorized_keys
 | 
						|
 | 
						|
# add it to authorized_keys but avoid adding it twice
 | 
						|
ak=$ssh_dir/authorized_keys
 | 
						|
[ ! grep "$ssh_key" $ak ] && echo "$ssh_key" >> $ak
 | 
						|
 | 
						|
# ssh wont work without it
 | 
						|
chmod -R 0700 /home/$login/.ssh
 | 
						|
chown -R $login:$login $ssh_dir
 |